Muthu Kumar
6 years ago
3 changed files with 46 additions and 11 deletions
@ -1,17 +1,19 @@ |
|||
const Promise = require('bluebird'); |
|||
const { isPromise } = require('../util'); |
|||
|
|||
const createRejectionStatement = (statement, ...args) => |
|||
Promise.reject(statement ? statement(...args) : ''); |
|||
|
|||
const _assertPromise = (bool, statementTuple) => { |
|||
|
|||
const [ statement, ...args ] = statementTuple; |
|||
if(isPromise(bool)) |
|||
return bool.catch(() => |
|||
createRejectionStatement(statement, ...args)); |
|||
|
|||
return bool |
|||
? Promise.resolve() |
|||
: createRejectionStatement(statement, ...args); |
|||
|
|||
}; |
|||
|
|||
module.exports = _assertPromise; |
|||
|
Loading…
Reference in new issue