node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

do-then

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...");
 
    });
 
});