async-promise-pool
Advanced tools
Comparing version 1.0.1-1 to 1.0.1
@@ -128,4 +128,4 @@ "use strict"; | ||
it("can be called multiple times", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() { | ||
var pool, results; | ||
it("should respect concurrency", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() { | ||
var delayedPromiseSpy, kindaDelayedPromiseProducer, delayedPromiseProducer, pool, results; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
@@ -135,16 +135,65 @@ while (1) { | ||
case 0: | ||
delayedPromiseSpy = jest.fn(); | ||
kindaDelayedPromiseProducer = function kindaDelayedPromiseProducer() { | ||
return new _promise2.default(function (resolve, reject) { | ||
setTimeout(function () { | ||
delayedPromiseSpy(); | ||
resolve("delayed2"); | ||
}, 500); | ||
}); | ||
}; | ||
delayedPromiseProducer = function delayedPromiseProducer() { | ||
return new _promise2.default(function (resolve, reject) { | ||
setTimeout(function () { | ||
delayedPromiseSpy(); | ||
resolve("delayed"); | ||
}, 1000); | ||
}); | ||
}; | ||
pool = new PromisePool({ concurrency: 2 }); | ||
pool.add(delayedPromiseProducer); | ||
pool.add(kindaDelayedPromiseProducer); | ||
pool.add(promiseProducer); | ||
_context4.next = 4; | ||
_context4.next = 9; | ||
return pool.all(); | ||
case 9: | ||
results = _context4.sent; | ||
expect(results[0]).toBe("delayed2"); | ||
expect(results[1]).toBe("success"); | ||
expect(results[2]).toBe("delayed"); | ||
case 13: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, undefined); | ||
}))); | ||
it("can be called multiple times", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() { | ||
var pool, results; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
pool = new PromisePool({ concurrency: 2 }); | ||
pool.add(promiseProducer); | ||
_context5.next = 4; | ||
return pool.all(); | ||
case 4: | ||
pool.add(promiseProducer); | ||
pool.add(promiseProducer); | ||
_context4.next = 8; | ||
_context5.next = 8; | ||
return pool.all(); | ||
case 8: | ||
results = _context4.sent; | ||
results = _context5.sent; | ||
@@ -156,13 +205,13 @@ expect(promiseSpy).toHaveBeenCalledTimes(3); | ||
case "end": | ||
return _context4.stop(); | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee4, undefined); | ||
}, _callee5, undefined); | ||
}))); | ||
it("should throw if .all fails", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() { | ||
it("should throw if .all fails", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() { | ||
var pool, error, errorProducer; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
@@ -178,3 +227,3 @@ pool = new PromisePool({ concurrency: 2 }); | ||
_context5.prev = 3; | ||
_context6.prev = 3; | ||
@@ -184,14 +233,14 @@ pool.add(promiseProducer); | ||
pool.add(errorProducer); | ||
_context5.next = 9; | ||
_context6.next = 9; | ||
return pool.all(); | ||
case 9: | ||
_context5.next = 14; | ||
_context6.next = 14; | ||
break; | ||
case 11: | ||
_context5.prev = 11; | ||
_context5.t0 = _context5["catch"](3); | ||
_context6.prev = 11; | ||
_context6.t0 = _context6["catch"](3); | ||
error = _context5.t0.message; | ||
error = _context6.t0.message; | ||
@@ -203,13 +252,13 @@ case 14: | ||
case "end": | ||
return _context5.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee5, undefined, [[3, 11]]); | ||
}, _callee6, undefined, [[3, 11]]); | ||
}))); | ||
it("should throw if any promise fails outside of .all", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() { | ||
it("should throw if any promise fails outside of .all", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() { | ||
var pool, error, errorProducer; | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
return _regenerator2.default.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
@@ -228,15 +277,15 @@ pool = new PromisePool({ concurrency: 2 }); | ||
pool.add(errorProducer); | ||
_context6.prev = 6; | ||
_context6.next = 9; | ||
_context7.prev = 6; | ||
_context7.next = 9; | ||
return pool.all(); | ||
case 9: | ||
_context6.next = 14; | ||
_context7.next = 14; | ||
break; | ||
case 11: | ||
_context6.prev = 11; | ||
_context6.t0 = _context6["catch"](6); | ||
_context7.prev = 11; | ||
_context7.t0 = _context7["catch"](6); | ||
error = _context6.t0.message; | ||
error = _context7.t0.message; | ||
@@ -248,7 +297,7 @@ case 14: | ||
case "end": | ||
return _context6.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee6, undefined, [[6, 11]]); | ||
}, _callee7, undefined, [[6, 11]]); | ||
}))); | ||
}); |
{ | ||
"name": "async-promise-pool", | ||
"version": "1.0.1-1", | ||
"version": "1.0.1", | ||
"description": "A flexible pool of promises that can be awaited and executed at a chosen level of concurrency", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15652
344
1