@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 2.5 kB
Source Map (JSON)
{"version":3,"sources":["asynciterable/operators/finalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,oBAA8B,SAAQ,cAAuB;IAIxE,YAAY,MAA8B,EAAE,MAAkC;QAC5E,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI;YACF,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC5D,MAAM,IAAI,CAAC;aACZ;SACF;gBAAS;YACR,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;SACtB;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAkC;IAElC,OAAO,SAAS,wBAAwB,CACtC,MAA8B;QAE9B,OAAO,IAAI,oBAAoB,CAAU,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC","file":"finalize.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class FinallyAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _action: () => any | Promise<any>;\n\n constructor(source: AsyncIterable<TSource>, action: () => void | Promise<void>) {\n super();\n this._source = source;\n this._action = action;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n try {\n for await (const item of wrapWithAbort(this._source, signal)) {\n yield item;\n }\n } finally {\n await this._action();\n }\n }\n}\n\n/**\n * Invokes a specified asynchronous action after the source async-iterable sequence terminates gracefully or exceptionally.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {(() => void | Promise<void>)} action Action to invoke and await asynchronously after the source async-iterable sequence terminates\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} An operator that returns the source sequence with the\n * action-invoking termination behavior applied.\n */\nexport function finalize<TSource>(\n action: () => void | Promise<void>\n): MonoTypeOperatorAsyncFunction<TSource> {\n return function finalizeOperatorFunction(\n source: AsyncIterable<TSource>\n ): AsyncIterableX<TSource> {\n return new FinallyAsyncIterable<TSource>(source, action);\n };\n}\n"]}