Created
June 27, 2022 21:45
-
-
Save jesseschalken/2ad205e2abd37ce99358ef604654ee3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ClientReadableStream } from "grpc-web"; | |
import { Observable } from "rxjs"; | |
export function grpcToRx<T>(f: () => ClientReadableStream<T>): Observable<T> { | |
return new Observable<T>(subscriber => { | |
const stream = f(); | |
stream.on("error", e => subscriber.error(e)); | |
stream.on("end", () => subscriber.complete()); | |
stream.on("data", x => subscriber.next(x)); | |
return () => stream.cancel(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment