promisif-node
v0.0.2
Published
wrapper to promise to do a if block
Downloads
2
Maintainers
Readme
promisif-node
promise flow with if cycle
Usage
const Pif = require('promisif-node')()
let i = 0
new Pif((resolve) => resolve())
.then(() => {
Pif.if(false);
return 'test';
})
.then(()=>i++)
.catch(()=>i++)
.then(() => Pif.end())
.then((val) => {
assert(val === 'test');
assert(i === 0);
});
let i = 0
Pif.reject()
.catch(() => {
Pif.if(false);
return 'test';
})
.then(()=>i++)
.then(()=>i++)
.catch(() => Pif.end())
.then((val) => {
assert(val === 'test');
assert(i === 0);
});
let i = 0
Pif.reject()
.catch(() => {
Pif.if(false);
return 'test';
})
.then(()=>i++)
.then(()=>i++)
.then(() => Pif.end())
.then((val) => {
assert(val === 'test');
assert(i === 0);
});
let i = 0
Pif.resolve()
.then(() => {
Pif.if(false);
return 'test';
})
.then(()=>i++)
.then(()=>i++)
.catch(() => Pif.end())
.then((val) => {
assert(val === 'test');
assert(i === 0);
});
new Pif((resolve) => resolve())
.then(() => {
Pif.if(false);
return Promise.reject('error');
})
.catch(()=>i++)
.catch(()=>i++)
.then(()=>i++)
.then(() => Pif.end())
.catch((error) => {
assert(error === 'error');
assert(i === 0);
});
Pif.reject()
.catch(() => {
Pif.if(false);
return Promise.reject('error');
})
.catch(()=>i++)
.catch(()=>i++)
.then(()=>i++)
.catch(() => Pif.end())
.catch((error) => {
assert(error === 'error');
assert(i === 0);
});
new Pif((resolve) => resolve())
.then(() => {
Pif.if(false);
return Promise.reject('error');
})
.catch(()=>i++)
.catch(()=>i++)
.then(()=>i++)
.catch(() => Pif.end())
.catch((error) => {
assert(error === 'error');
assert(i === 0);
});
new Pif((resolve) => resolve())
.catch(() => {
Pif.if(false);
return Promise.reject('error');
})
.catch(()=>i++)
.catch(()=>i++)
.then(()=>i++)
.then(() => Pif.end())
.catch((error) => {
assert(error === 'error');
assert(i === 0);
});
new Pif((resolve) => resolve())
.catch(() => {
Pif.if(true);
return Promise.reject('error');
})
.catch(()=>i++)
.then(()=>i++)
.then(()=>i++)
.then(() => Pif.end())
.catch((error) => {
assert(error === 'error');
assert(i === 3);
});
API
Class Method
resolve(val)
return a resolved if-promise.
reject(val)
return a rejected if-promise.
if(bool)
init the conditional block if bool is true.
end()
finish the conditional block. You can called in any time, could be a then method or catch method.
Instance Method
then(res,rej) -> if-promise
wrapper to then promise method.
catch(rej) -> if-promise
wrapper to catch promise method.