README
HOW TO USE
this is module is built to make promise very easily.
The module export a function which it returns a Promise.
The function take three arguments. The first is a boolean, or better, a function that returne a boolean. This boolean sets if the function will return a rejected Promise or a resolved Promise.
The first argument is the value to resolve.
The second argument is the value to reject.
The third is a boolean, or better, a function that returne a boolean. This boolean sets if the function will return a rejected Promise or a resolved Promise.
Example
const pomProm = require('pomprom')
//A very simple way to returned a resolved Promise
pomProm('hello').then((msg) => console.log(msg)) // => 'hello'
//A very simple way to returned a rejected Promise
pomProm(null, 'I am rejected').then(null, (msg) => console.log(msg)) // => 'I am rejected'
//The following example always returns a rejected Promise
pomProm('Resolved', 'Rejected', true)n
.then((msg1) => console.log(msg1), (msg2) => console.log(msg2)) // => 'Rejected'
//a better way to use this module
var arr = [2, 4, 6, 8]
function isEven (item) {
if (item % 2 === 0) {
return true
} else {
return false
}
}
pomProm('All values are even', 'Not all values are even',
arr.every( (item) => (! isEven(item) )))
.then( (msg) => console.log(msg), (otherMsg) => console.log(otherMsg))
API
pomProm : allValues * allValues * Boolean -> Promise
pomProm(toResolve[, toReject][, ifRejected])
toResolve : Any value that will be passed to the Promise if it resolved
toReject : Anu value that will be passed to the Promise if it rejected
ifRejected : Boolean