UNPKG

ix

Version:

The Interactive Extensions for JavaScript

60 lines (58 loc) 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.take = exports.TakeAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("../asynciterablex.js"); const withabort_js_1 = require("./withabort.js"); const aborterror_js_1 = require("../../aborterror.js"); /** @ignore */ class TakeAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(source, count) { super(); this._source = source; this._count = count; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { var _b, e_1, _c, _d; (0, aborterror_js_1.throwIfAborted)(signal); let i = this._count; if (i > 0) { try { for (var _e = true, _f = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._source, signal)), _g; _g = yield tslib_1.__await(_f.next()), _b = _g.done, !_b; _e = true) { _d = _g.value; _e = false; const item = _d; yield yield tslib_1.__await(item); if (--i === 0) { break; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_e && !_b && (_c = _f.return)) yield tslib_1.__await(_c.call(_f)); } finally { if (e_1) throw e_1.error; } } } }); } } exports.TakeAsyncIterable = TakeAsyncIterable; /** * Returns a specified number of contiguous elements from the start of an async-iterable sequence. * * @template TSource The type of the elements in the source sequence. * @param {number} count The number of elements to return. * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence that contains the specified * number of elements from the start of the input sequence. */ function take(count) { return function takeOperatorFunction(source) { return new TakeAsyncIterable(source, count); }; } exports.take = take; //# sourceMappingURL=take.js.map