@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 1.64 kB
Source Map (JSON)
{"version":3,"sources":["asynciterable/operators/finalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,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;QAC3B,IAAI;YACF,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;gBACrC,MAAM,IAAI,CAAC;aACZ;SACF;gBAAS;YACR,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;SACtB;IACH,CAAC;CACF;AAED,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';\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]() {\n try {\n for await (const item of this._source) {\n yield item;\n }\n } finally {\n await this._action();\n }\n }\n}\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"]}