Comparing version 0.4.0 to 1.0.0
33
index.js
@@ -1,28 +0,27 @@ | ||
var _stackOfMore = []; | ||
var _noMore = false; | ||
var _stackOfMore = [] | ||
var _noMore = false | ||
/** | ||
* add a Promise or function that returns a 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"); | ||
var toPush = more; | ||
if (more instanceof Function) toPush = more(); | ||
if (!(toPush instanceof Promise)) | ||
throw new Error("but-wait: expected Promise as return, got " + toPush.constructor.name); | ||
var thereIsMore = function (more) { | ||
if (_noMore) throw new Error('but-wait: you must not add more after noMore was called') | ||
var toPush = more | ||
if (more instanceof Function) toPush = more() | ||
if (!(toPush instanceof Promise)) { throw new Error('but-wait: expected Promise as return, got ' + toPush.constructor.name) } | ||
_stackOfMore.push(toPush); | ||
}; | ||
_stackOfMore.push(toPush) | ||
} | ||
/** | ||
* 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); | ||
}; | ||
var noMore = function () { | ||
_noMore = true | ||
return Promise.all(_stackOfMore) | ||
} | ||
@@ -32,2 +31,2 @@ module.exports = { | ||
noMore: noMore | ||
}; | ||
} |
{ | ||
"name": "but-wait", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"description": "but wait, there is more! run parallel tasks synchronously after initializing but before starting your application", | ||
@@ -11,3 +11,11 @@ "main": "index.js", | ||
"author": "Nikita Malyschkin", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^5.9.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^8.0.0", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0" | ||
} | ||
} |
@@ -1,17 +0,17 @@ | ||
const butWait = require("../index"); | ||
const assert = require('assert').strict; | ||
const butWait = require('../index') | ||
const assert = require('assert').strict | ||
let flag = 0; | ||
let flag = 0 | ||
// to be resolved | ||
let resolve1; | ||
const prom1 = new Promise( res => {resolve1 = res} ).then(() => { | ||
assert.ok(flag === 0); | ||
flag = 1; | ||
}); | ||
butWait.thereIsMore(prom1); | ||
let resolve1 | ||
const prom1 = new Promise(resolve => { resolve1 = resolve }).then(() => { | ||
assert.ok(flag === 0) | ||
flag = 1 | ||
}) | ||
butWait.thereIsMore(prom1) | ||
// already resolved | ||
const prom2 = new Promise( res => res() ); | ||
butWait.thereIsMore(prom2); | ||
const prom2 = new Promise(resolve => resolve()) | ||
butWait.thereIsMore(prom2) | ||
@@ -23,3 +23,3 @@ // more is not a promise | ||
assert.throws(() => { | ||
butWait.thereIsMore("test") | ||
butWait.thereIsMore('test') | ||
}) | ||
@@ -32,5 +32,5 @@ assert.throws(() => { | ||
butWait.noMore().then(() => { | ||
assert.ok(flag === 1); | ||
flag = 2; | ||
}); | ||
assert.ok(flag === 1) | ||
flag = 2 | ||
}) | ||
@@ -42,10 +42,10 @@ // throw if noMore was called already | ||
resolve1(); | ||
new Promise(res => res()) | ||
resolve1() | ||
new Promise(resolve => resolve()) | ||
.then(() => { | ||
assert.ok(flag === 1); | ||
assert.ok(flag === 1) | ||
}) | ||
.then() // noMore() gets resolved | ||
.then(() => { | ||
assert.ok(flag === 2); | ||
}) | ||
assert.ok(flag === 2) | ||
}) |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3788
5
73
2
6