Comparing version 0.1.1 to 0.2.0
27
index.js
var _stackOfMore = []; | ||
var _noMore = false; | ||
/** | ||
* add function | ||
* add a Promise or function that returns a Promise | ||
* | ||
* @param {function} more called without any parameters, expected to return Promise | ||
* @param {function/Promise} more if function called without any parameters, expected to return Promise | ||
*/ | ||
var thereIsMore = function(more) { | ||
if (_noMore) throw new Error("but-wait: you must not add more after noMore was called"); | ||
if (!(more instanceof Function)) | ||
throw new Error("but-wait: 'thereIsMore' must be called with a function that return a Promise"); | ||
stackOfMore.push(more); | ||
let toPush = more; | ||
if (more instanceof Function) toPush = more(); | ||
if (!(toPush instanceof Promise)) | ||
throw new Error("but-wait: expected Promise as return, got " + prom.constructor.name); | ||
_stackOfMore.push(more); | ||
}; | ||
/** | ||
* call when no more should be added | ||
* | ||
* @returns {Promise} Promise that is resolved when all asynchronous initializations finished | ||
*/ | ||
var noMore = function() { | ||
_noMore = true; | ||
return Promise.all([ | ||
stackOfMore.map(function(more) { | ||
var prom = more(); | ||
if (prom instanceof Promise) return prom; | ||
else throw new Error("but-wait: expected Promise as return, got " + prom.constructor.name); | ||
}) | ||
]); | ||
return Promise.all(_stackOfMore); | ||
}; | ||
@@ -25,0 +28,0 @@ |
{ | ||
"name": "but-wait", | ||
"version": "0.1.1", | ||
"description": "", | ||
"version": "0.2.0", | ||
"description": "but wait, there is more! run parallel tasks synchronously after initializing but before starting your application", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
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
1277
28