do-then
v1.0.1
Published
Realise sync or async tasks as promises, resolve to do the next step or reject and catch an error.
Downloads
4
Maintainers
Readme
DO-THEN
Realise sync or async tasks as promises, resolve to do the next step or reject and catch an error.
INSTALL
npm i do-then
USE / EXAMPLE
new Do(function( resolve, reject ){
resolve("nope");
})
.then(function( resolve, reject, promise ){
if( promise == "foo" ){
resolve("bar");
}
else {
reject("promise is not equal to 'foo' but '" + promise + "'");
};
})
.then(function( resolve, reject, promise ){
if( promise == "bar" ){
console.info("Promise is correct");
}
else {
reject("Promise is not correct");
};
})
.catch(function( retry, promise ){
console.error("catch error: ", promise);
retry(false, function( resolve, reject ){
console.log("restart")
resolve("foo");
}, function( retry, promise ){
console.error("Cant do nothing at all...");
});
});