Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mergeiterator

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mergeiterator - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

distr/mergeiterator.js.flow

134

distr/mergeiterator.js

@@ -6,47 +6,44 @@ "use strict";

});
var _promise = require("babel-runtime/core-js/promise");
var _promise2 = _interopRequireDefault(_promise);
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _iterator = require("babel-runtime/core-js/symbol/iterator");
var _iterator2 = _interopRequireDefault(_iterator);
var _symbol = require("babel-runtime/core-js/symbol");
var _symbol2 = _interopRequireDefault(_symbol);
exports.default = merge;
function _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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (!Symbol.asyncIterator) {
Symbol.asyncIterator = Symbol("asyncIterator");
}
const getIterator = iterable => typeof iterable[_symbol2.default.asyncIterator] === "function" ? iterable[_symbol2.default.asyncIterator]() : typeof iterable[_iterator2.default] === "function" ? (0, _getIterator3.default)(iterable) : typeof iterable.next === "function" ? iterable : iterable[_symbol2.default.asyncIterator]();
var getIterator = function getIterator(iterable) {
return typeof iterable[Symbol.asyncIterator] === "function" ? iterable[Symbol.asyncIterator]() : typeof iterable[Symbol.iterator] === "function" ? iterable[Symbol.iterator]() : typeof iterable.next === "function" ? iterable : iterable[Symbol.asyncIterator]();
};
const resolveDone = value => ({ value, done: true });
const resolveNotDone = value => ({ value, done: false });
const resolveRecord = ({ value, done }) => _promise2.default.resolve(value).then(done ? resolveDone : resolveNotDone);
const resolveThenable = promise => _promise2.default.resolve(promise).then(resolveRecord);
var resolveDone = function resolveDone(value) {
return { value: value, done: true };
};
var resolveNotDone = function resolveNotDone(value) {
return { value: value, done: false };
};
var resolveRecord = function resolveRecord(_ref) {
var value = _ref.value,
done = _ref.done;
return Promise.resolve(value).then(done ? resolveDone : resolveNotDone);
};
var resolveThenable = function resolveThenable(promise) {
return Promise.resolve(promise).then(resolveRecord);
};
function merge(sequences) {
var _iterator;
const sequenceIterator = getIterator(sequences);
const ticks = [];
const results = [];
const resolvers = [];
const returnedValues = [];
let mergeResult = { value: returnedValues, done: true };
let mergeResover,
mergePromise = new _promise2.default(resolve => mergeResover = resolve);
let inputClosed = false;
let outputClosed = false;
let count = 0;
let remainingIterators = 1;
var sequenceIterator = getIterator(sequences);
var ticks = [];
var results = [];
var resolvers = [];
var returnedValues = [];
var mergeResult = { value: returnedValues, done: true };
var mergeResover = void 0,
mergePromise = new Promise(function (resolve) {
return mergeResover = resolve;
});
var inputClosed = false;
var outputClosed = false;
var count = 0;
var remainingIterators = 1;
function copyResults() {

@@ -93,11 +90,8 @@ while (!outputClosed && resolvers.length > 0 && results.length > 0) {

if (typeof iterator.return === "function") {
resolveThenable(iterator.return()).then(function (_ref2) {
var value = _ref2.value,
done = _ref2.done;
resolveThenable(iterator.return()).then(({ value, done }) => {
if (done) {
returnedValues[returnIndex] = value;
}
}, function (error) {
mergeResult = Promise.reject(error);
}, error => {
mergeResult = _promise2.default.reject(error);
}).then(iteratorFinished);

@@ -114,7 +108,4 @@ } else {

function nextSeq() {
var sequencePromise = resolveThenable(sequenceIterator.next());
sequencePromise.then(function onSequenceResolve(_ref3) {
var value = _ref3.value,
done = _ref3.done;
const sequencePromise = resolveThenable(sequenceIterator.next());
sequencePromise.then(function onSequenceResolve({ value, done }) {
if (done) {

@@ -124,12 +115,13 @@ returnedValues.value = value;

} else {
var closeValue = function closeValue() {
++remainingIterators;
const index = count++;
const valueIterator = getIterator(value);
function closeValue() {
closeIterator(valueIterator, index);
};
}
var nextValue = function nextValue() {
var valuePromise = resolveThenable(valueIterator.next());
valuePromise.then(function onValueResolve(_ref4) {
var value = _ref4.value,
done = _ref4.done;
function nextValue() {
const valuePromise = resolveThenable(valueIterator.next());
valuePromise.then(function onValueResolve({ value, done }) {
if (done) {

@@ -147,8 +139,4 @@ returnedValues[index] = value;

});
};
}
++remainingIterators;
var index = count++;
var valueIterator = getIterator(value);
nextValue();

@@ -171,16 +159,14 @@ pushNext(nextSeq, closeSeq);

var iterator = (_iterator = {}, _defineProperty(_iterator, Symbol.asyncIterator, function () {
return iterator;
}), _defineProperty(_iterator, "next", function next() {
return new Promise(function (resolve) {
const iterator = {
[_symbol2.default.asyncIterator]: () => iterator,
next: () => new _promise2.default(resolve => {
resolvers.push(resolve);
copyResults();
});
}), _defineProperty(_iterator, "return", function _return(value) {
return new Promise(function (resolve) {
}),
return: value => new _promise2.default(resolve => {
if (resolvers.length === 0) {
finish();
} else {
var last = resolvers.pop();
resolvers.push(function (value) {
const last = resolvers.pop();
resolvers.push(value => {
last(value);

@@ -192,8 +178,8 @@ finish();

outputClosed = true;
mergeResult = { value: value, done: true };
mergeResult = { value, done: true };
resolve(mergePromise);
close();
}
});
}), _iterator);
})
};

@@ -200,0 +186,0 @@ return iterator;

{
"name": "mergeiterator",
"version": "1.1.3",
"version": "1.1.4",
"description": "merges async iterators",

@@ -13,7 +13,10 @@ "keywords": [

"repository": "https://github.com/vadzim/mergeiterator",
"author": "developer@vadzim.info",
"bugs": {
"url": "https://github.com/vadzim/mergeiterator/issues"
},
"contributors": [],
"main": "distr/mergeiterator.js",
"author": "Vadzim Zieńka <developer@vadzim.info>",
"scripts": {
"build": "babel source --out-dir distr",
"build": "babel source --out-dir distr && cd distr && (for f in $(find | grep -E '.js$'); do cp ../source/$f $f.flow; done) && cd ..",
"prettier": "prettier --write $(cat .prettier) 'source/**/*.js' 'example/**/*.js' '*.js'",

@@ -25,14 +28,18 @@ "prepare": "npm run build",

"license": "MIT",
"bugs": {
"url": "https://github.com/vadzim/mergeiterator/issues"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-idx": "^2.0.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-stage-0": "^6.24.1",
"jest": "^20.0.4",
"prettier": "^1.5.3"
"flow-bin": "^0.56.0",
"idx": "^1.5.0",
"jest": "^21.2.1",
"prettier": "^1.7.4"
},
"dependencies": {
"babel-runtime": "^6.26.0"
}
}

@@ -1,2 +0,2 @@

# mergeIterator
# mergeiterator
Merges async iterators.

@@ -8,2 +8,6 @@

```js
merge(collection_of_iterables): Iterable
```
Pass it a collection of iterables and it'll return an [async iterator](https://github.com/tc39/proposal-async-iteration), which will contain all values from those iterables. Those iterables and the collection of them can be arrays, calls to generators, or any other kind of iterable, synchronous or async, finite or infinite.

@@ -10,0 +14,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc