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,CAAC,CAAC;iBACrB;YACH,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QACF,CAAC,EAAE,CAAC;QAEJ,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAU,MAA8B;IAClE,OAAO,IAAI,uBAAuB,CAAU,MAAM,CAAC,CAAC;AACtD,CAAC","file":"toobservable.js","sourcesContent":["import { toObserver } from '../util/toobserver';\nimport { observable as symbolObservable } from '../observer';\nimport { Observable, PartialObserver } from '../observer';\nimport { Subscription } from '../subscription';\n\nclass BooleanSubscription implements Subscription {\n public isUnsubscribed: boolean = false;\n\n unsubscribe() {\n this.isUnsubscribed = true;\n }\n}\n\nclass AsyncIterableObservable<TSource> implements Observable<TSource> {\n private _source: AsyncIterable<TSource>;\n\n constructor(source: AsyncIterable<TSource>) {\n this._source = source;\n }\n\n [symbolObservable](): Observable<TSource> {\n return this;\n }\n subscribe(\n next?: PartialObserver<TSource> | ((value: TSource) => any) | null,\n error?: ((err: any) => any) | null,\n complete?: (() => any) | null\n ) {\n const observer = toObserver(next, error, complete);\n const subscription = new BooleanSubscription();\n\n const it = this._source[Symbol.asyncIterator]();\n const f = () => {\n it.next()\n .then(({ value, done }) => {\n if (!subscription.isUnsubscribed) {\n if (done) {\n observer.complete();\n } else {\n observer.next(value);\n f();\n }\n }\n })\n .catch((err) => {\n if (!subscription.isUnsubscribed) {\n observer.error(err);\n }\n });\n };\n f();\n\n return subscription;\n }\n}\n\n/**\n * Converts the async-iterable sequence to an observable.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {AsyncIterable<TSource>} source The async-iterable to convert to an observable.\n * @returns {Observable<TSource>} The observable containing the elements from the async-iterable.\n */\nexport function toObservable<TSource>(source: AsyncIterable<TSource>): Observable<TSource> {\n return new AsyncIterableObservable<TSource>(source);\n}\n"]}
\No newline at end of file