UNPKG

abort-controller-x-rxjs

Version:
22 lines 693 B
import { Observable } from 'rxjs'; /** * Turns abortable async generator to observable. */ export function fromAsyncGenerator(fn) { return new Observable(subscriber => { const abortController = new AbortController(); async function iterate() { for await (const item of fn(abortController.signal)) { if (subscriber.closed) { return; } subscriber.next(item); } } iterate().then(() => subscriber.complete(), err => subscriber.error(err)); return () => { abortController.abort(); }; }); } //# sourceMappingURL=fromAsyncGenerator.js.map