Skip to content

Instantly share code, notes, and snippets.

@jesseschalken
Created June 27, 2022 21:45
Show Gist options
  • Save jesseschalken/2ad205e2abd37ce99358ef604654ee3c to your computer and use it in GitHub Desktop.
Save jesseschalken/2ad205e2abd37ce99358ef604654ee3c to your computer and use it in GitHub Desktop.
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