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 { isPromise } = require('../util'); |
||||
|
|
||||
const createRejectionStatement = (statement, ...args) => |
const createRejectionStatement = (statement, ...args) => |
||||
Promise.reject(statement ? statement(...args) : ''); |
Promise.reject(statement ? statement(...args) : ''); |
||||
|
|
||||
const _assertPromise = (bool, statementTuple) => { |
const _assertPromise = (bool, statementTuple) => { |
||||
|
|
||||
const [ statement, ...args ] = statementTuple; |
const [ statement, ...args ] = statementTuple; |
||||
if(isPromise(bool)) |
if(isPromise(bool)) |
||||
return bool.catch(() => |
return bool.catch(() => |
||||
createRejectionStatement(statement, ...args)); |
createRejectionStatement(statement, ...args)); |
||||
|
|
||||
return bool |
return bool |
||||
? Promise.resolve() |
? Promise.resolve() |
||||
: createRejectionStatement(statement, ...args); |
: createRejectionStatement(statement, ...args); |
||||
|
|
||||
}; |
}; |
||||
|
|
||||
module.exports = _assertPromise; |
module.exports = _assertPromise; |
||||
|
Loading…
Reference in new issue