maximize-iterator
Advanced tools
@@ -21,6 +21,4 @@ "use strict"; | ||
| function processDone(err, options, callback) { | ||
| // mark this iteration done | ||
| options.err = options.err || err; | ||
| options.done = true; | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
@@ -32,3 +30,2 @@ callback(options.err, options.done); | ||
| options.counter--; | ||
| // mark this iteration done | ||
| if (err && _asynccompat.default.defaultValue(options.error(err), false) || !err && !_asynccompat.default.defaultValue(keep, true)) { | ||
@@ -38,3 +35,2 @@ options.err = options.err || err; | ||
| } | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
@@ -45,8 +41,10 @@ callback(options.err, options.done); | ||
| function createProcessor(next, options, callback) { | ||
| var isProcessing = false; | ||
| return function processor(doneOrError) { | ||
| var error = doneOrError; | ||
| if (doneOrError && processDone(isError(error) ? error : null, options, callback)) return; | ||
| if (isProcessing) return; | ||
| isProcessing = true; | ||
| var flushing = false; | ||
| function callDefer(err, keep) { | ||
| var shouldContinue = !processResult(err, keep, options, callback); | ||
| if (flushing) return; | ||
| if (shouldContinue) flush(); | ||
| } | ||
| function flush() { | ||
| flushing = true; | ||
| while(options.counter < options.concurrency){ | ||
@@ -56,2 +54,3 @@ if (options.done || !options.canProcess()) break; | ||
| processDone(null, options, callback); | ||
| flushing = false; | ||
| return; | ||
@@ -63,12 +62,17 @@ } | ||
| if (err || result.done) { | ||
| return !processResult(err, false, options, callback) && !isProcessing ? processor() : undefined; | ||
| return callDefer(err, false); | ||
| } | ||
| _asynccompat.default.asyncFunction(options.each, options.callbacks, result.value, function(err, keep) { | ||
| return !processResult(err, keep, options, callback) && !isProcessing ? processor() : undefined; | ||
| return callDefer(err, keep); | ||
| }); | ||
| }); | ||
| } | ||
| isProcessing = false; | ||
| flushing = false; | ||
| } | ||
| return function processor(doneOrError) { | ||
| var error = doneOrError; | ||
| if (doneOrError && processDone(isError(error) ? error : null, options, callback)) return; | ||
| flush(); | ||
| }; | ||
| } | ||
| /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; } |
| import compat from 'async-compat'; | ||
| const isError = (err)=>err && err.stack !== undefined && err.message !== undefined; | ||
| function processDone(err, options, callback) { | ||
| // mark this iteration done | ||
| options.err = options.err || err; | ||
| options.done = true; | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
@@ -14,3 +12,2 @@ callback(options.err, options.done); | ||
| options.counter--; | ||
| // mark this iteration done | ||
| if (err && compat.defaultValue(options.error(err), false) || !err && !compat.defaultValue(keep, true)) { | ||
@@ -20,3 +17,2 @@ options.err = options.err || err; | ||
| } | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
@@ -27,8 +23,10 @@ callback(options.err, options.done); | ||
| export default function createProcessor(next, options, callback) { | ||
| let isProcessing = false; | ||
| return function processor(doneOrError) { | ||
| const error = doneOrError; | ||
| if (doneOrError && processDone(isError(error) ? error : null, options, callback)) return; | ||
| if (isProcessing) return; | ||
| isProcessing = true; | ||
| let flushing = false; | ||
| function callDefer(err, keep) { | ||
| const shouldContinue = !processResult(err, keep, options, callback); | ||
| if (flushing) return; | ||
| if (shouldContinue) flush(); | ||
| } | ||
| function flush() { | ||
| flushing = true; | ||
| while(options.counter < options.concurrency){ | ||
@@ -38,2 +36,3 @@ if (options.done || !options.canProcess()) break; | ||
| processDone(null, options, callback); | ||
| flushing = false; | ||
| return; | ||
@@ -45,9 +44,14 @@ } | ||
| if (err || result.done) { | ||
| return !processResult(err, false, options, callback) && !isProcessing ? processor() : undefined; | ||
| return callDefer(err, false); | ||
| } | ||
| compat.asyncFunction(options.each, options.callbacks, result.value, (err, keep)=>!processResult(err, keep, options, callback) && !isProcessing ? processor() : undefined); | ||
| compat.asyncFunction(options.each, options.callbacks, result.value, (err, keep)=>callDefer(err, keep)); | ||
| }); | ||
| } | ||
| isProcessing = false; | ||
| flushing = false; | ||
| } | ||
| return function processor(doneOrError) { | ||
| const error = doneOrError; | ||
| if (doneOrError && processDone(isError(error) ? error : null, options, callback)) return; | ||
| flush(); | ||
| }; | ||
| } |
+3
-3
| { | ||
| "name": "maximize-iterator", | ||
| "version": "4.1.0", | ||
| "version": "4.2.0", | ||
| "description": "Maximize the parallel calls of an iterator supporting asyncIterator interface", | ||
@@ -44,4 +44,4 @@ "keywords": [ | ||
| "dependencies": { | ||
| "async-compat": ">=1.4.6", | ||
| "iterator-next-callback": ">=1.1.4" | ||
| "async-compat": "^1.4.6", | ||
| "iterator-next-callback": "^2.1.0" | ||
| }, | ||
@@ -48,0 +48,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
49648
0.19%368
2.22%+ Added
- Removed
Updated