ix
Version:
The Interactive Extensions for JavaScript
37 lines (35 loc) • 1.4 kB
JavaScript
import { __asyncValues, __awaiter } from "tslib";
import { wrapWithAbort } from './operators/withabort.mjs';
import { throwIfAborted } from '../aborterror.mjs';
/**
* Converts an existing async-iterable to a promise containing the array of values.
*
* @template TSource The type of elements in the source sequence.
* @param {AsyncIterable<TSource>} source The source sequence to convert to an array.
* @param {AbortSignal} [signal] An optional abort signal to cancel the operation at any time.
* @returns {Promise<TSource[]>} A promise containing all the items from the source sequence as an array.
*/
export function toArray(source, signal) {
var _a, e_1, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
throwIfAborted(signal);
const results = [];
try {
for (var _d = true, _e = __asyncValues(wrapWithAbort(source, signal)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const item = _c;
results.push(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
return results;
});
}
//# sourceMappingURL=toarray.mjs.map