source: trip-planner-front/node_modules/readable-stream/lib/internal/streams/from.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[6a3a178]1'use strict';
2
3function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
5function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
7function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
8
9function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
10
11function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
13var ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE;
14
15function from(Readable, iterable, opts) {
16 var iterator;
17
18 if (iterable && typeof iterable.next === 'function') {
19 iterator = iterable;
20 } else if (iterable && iterable[Symbol.asyncIterator]) iterator = iterable[Symbol.asyncIterator]();else if (iterable && iterable[Symbol.iterator]) iterator = iterable[Symbol.iterator]();else throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable);
21
22 var readable = new Readable(_objectSpread({
23 objectMode: true
24 }, opts)); // Reading boolean to protect against _read
25 // being called before last iteration completion.
26
27 var reading = false;
28
29 readable._read = function () {
30 if (!reading) {
31 reading = true;
32 next();
33 }
34 };
35
36 function next() {
37 return _next2.apply(this, arguments);
38 }
39
40 function _next2() {
41 _next2 = _asyncToGenerator(function* () {
42 try {
43 var _ref = yield iterator.next(),
44 value = _ref.value,
45 done = _ref.done;
46
47 if (done) {
48 readable.push(null);
49 } else if (readable.push((yield value))) {
50 next();
51 } else {
52 reading = false;
53 }
54 } catch (err) {
55 readable.destroy(err);
56 }
57 });
58 return _next2.apply(this, arguments);
59 }
60
61 return readable;
62}
63
64module.exports = from;
Note: See TracBrowser for help on using the repository browser.