node-powertools
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -107,2 +107,6 @@ (function (root, factory) { | ||
}); | ||
} | ||
Powertools.queue = function (fn) { | ||
return new FunctionQueue(fn); | ||
} | ||
@@ -296,1 +300,49 @@ | ||
})); | ||
// FunctionQueue.js | ||
function FunctionQueue() { | ||
var self = this; | ||
self.queue = []; | ||
self.running = false; | ||
} | ||
FunctionQueue.prototype.enqueue = function (fn) { | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
self.queue.push({ | ||
function: fn, | ||
resolve: resolve, | ||
reject: reject | ||
}); | ||
self.process(); | ||
}); | ||
} | ||
FunctionQueue.prototype.process = function () { | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
if (self.running || !self.queue.length) { | ||
return resolve(); | ||
} | ||
self.running = true; | ||
var current = self.queue.shift(); | ||
current | ||
.function() | ||
.then(function(result) { | ||
current.resolve(result); | ||
}) | ||
.catch(function(err) { | ||
current.reject(err); | ||
}) | ||
.finally(function() { | ||
self.running = false; | ||
self.process(); | ||
}); | ||
}); | ||
} |
{ | ||
"name": "node-powertools", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "Powerful assistive functions for Node and Browser environments.", | ||
@@ -8,3 +8,3 @@ "main": "dist/index.js", | ||
"test": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000", | ||
"prepare": "node -e 'require(`prepare-package`)'" | ||
"prepare": "node -e 'require(`prepare-package`)()'" | ||
}, | ||
@@ -31,5 +31,5 @@ "engines": { | ||
"devDependencies": { | ||
"mocha": "^8.0.1", | ||
"prepare-package": "^0.0.13" | ||
"mocha": "^8.4.0", | ||
"prepare-package": "^0.0.16" | ||
} | ||
} | ||
} |
@@ -89,3 +89,3 @@ <p align="center"> | ||
// Call this function every 100 ms until it returns true or 30000 ms passes | ||
await powertools.poll(function () { | ||
await powertools.poll(function (index) { | ||
return something === somethingElse; | ||
@@ -92,0 +92,0 @@ }, {interval: 100, timeout: 30000}); |
@@ -107,2 +107,6 @@ (function (root, factory) { | ||
}); | ||
} | ||
Powertools.queue = function (fn) { | ||
return new FunctionQueue(fn); | ||
} | ||
@@ -296,1 +300,49 @@ | ||
})); | ||
// FunctionQueue.js | ||
function FunctionQueue() { | ||
var self = this; | ||
self.queue = []; | ||
self.running = false; | ||
} | ||
FunctionQueue.prototype.enqueue = function (fn) { | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
self.queue.push({ | ||
function: fn, | ||
resolve: resolve, | ||
reject: reject | ||
}); | ||
self.process(); | ||
}); | ||
} | ||
FunctionQueue.prototype.process = function () { | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
if (self.running || !self.queue.length) { | ||
return resolve(); | ||
} | ||
self.running = true; | ||
var current = self.queue.shift(); | ||
current | ||
.function() | ||
.then(function(result) { | ||
current.resolve(result); | ||
}) | ||
.catch(function(err) { | ||
current.reject(err); | ||
}) | ||
.finally(function() { | ||
self.running = false; | ||
self.process(); | ||
}); | ||
}); | ||
} |
@@ -21,2 +21,16 @@ const package = require('../package.json'); | ||
// describe('.queue()', () => { | ||
// describe('queue', () => { | ||
// // Normal | ||
// it('object (one key) => array (one key)', () => { | ||
// return assert.deepEqual(powertools.getKeys({name: 'ian'}), ['name']); | ||
// }); | ||
// it('object (one key + nested) => array (one key, nested)', () => { | ||
// return assert.deepEqual(powertools.getKeys({name: 'ian', favorites: {color: 'red'}}), ['name', 'favorites.color']); | ||
// }); | ||
// }); | ||
// }); | ||
describe('.getKeys()', () => { | ||
@@ -23,0 +37,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38729
832