summaryrefslogtreecommitdiffstats
path: root/middleware/node_modules/asynckit/serialOrdered.js
diff options
context:
space:
mode:
authorkrakenrf <>2022-10-27 13:26:32 +0200
committerkrakenrf <>2022-10-27 13:26:32 +0200
commit2127e196322d8c21124dcd15d28fe43b9f8b8ddb (patch)
tree258204ef95239e3923df769e4797c77048da2bfd /middleware/node_modules/asynckit/serialOrdered.js
parentadd middleware folder (diff)
downloadkrakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.tar
krakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.tar.gz
krakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.tar.bz2
krakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.tar.lz
krakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.tar.xz
krakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.tar.zst
krakensdr_pr-2127e196322d8c21124dcd15d28fe43b9f8b8ddb.zip
Diffstat (limited to 'middleware/node_modules/asynckit/serialOrdered.js')
-rw-r--r--middleware/node_modules/asynckit/serialOrdered.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/middleware/node_modules/asynckit/serialOrdered.js b/middleware/node_modules/asynckit/serialOrdered.js
new file mode 100644
index 0000000..607eafe
--- /dev/null
+++ b/middleware/node_modules/asynckit/serialOrdered.js
@@ -0,0 +1,75 @@
+var iterate = require('./lib/iterate.js')
+ , initState = require('./lib/state.js')
+ , terminator = require('./lib/terminator.js')
+ ;
+
+// Public API
+module.exports = serialOrdered;
+// sorting helpers
+module.exports.ascending = ascending;
+module.exports.descending = descending;
+
+/**
+ * Runs iterator over provided sorted array elements in series
+ *
+ * @param {array|object} list - array or object (named list) to iterate over
+ * @param {function} iterator - iterator to run
+ * @param {function} sortMethod - custom sort function
+ * @param {function} callback - invoked when all elements processed
+ * @returns {function} - jobs terminator
+ */
+function serialOrdered(list, iterator, sortMethod, callback)
+{
+ var state = initState(list, sortMethod);
+
+ iterate(list, iterator, state, function iteratorHandler(error, result)
+ {
+ if (error)
+ {
+ callback(error, result);
+ return;
+ }
+
+ state.index++;
+
+ // are we there yet?
+ if (state.index < (state['keyedList'] || list).length)
+ {
+ iterate(list, iterator, state, iteratorHandler);
+ return;
+ }
+
+ // done here
+ callback(null, state.results);
+ });
+
+ return terminator.bind(state, callback);
+}
+
+/*
+ * -- Sort methods
+ */
+
+/**
+ * sort helper to sort array elements in ascending order
+ *
+ * @param {mixed} a - an item to compare
+ * @param {mixed} b - an item to compare
+ * @returns {number} - comparison result
+ */
+function ascending(a, b)
+{
+ return a < b ? -1 : a > b ? 1 : 0;
+}
+
+/**
+ * sort helper to sort array elements in descending order
+ *
+ * @param {mixed} a - an item to compare
+ * @param {mixed} b - an item to compare
+ * @returns {number} - comparison result
+ */
+function descending(a, b)
+{
+ return -1 * ascending(a, b);
+}