qall
lift functions of any arity into a Promises/A+ chain
usage example
var qall = var await = awaitvar join = join { ifx !== y throw } // qall lets us not care whether `hashPass` and `checkHashInDB` are// sync or async // with `await`, we can curry the function argument of `qall`var assertEqAsync = qall qall qall
api
qall : (fn: Function, ...args: Promise|Any) => Promise
resolved with the return value of fn
qall.await : (fn: Function<T>) => Function<Promise<T>>
Wraps a fn
to let any of its args be a promise. That is, it
curries qall
with the fn
parameter.
qall.join : (...Promise || Array<Promise>) => Promise
joins multiple threads of execution and returns a promise
qall.spread : (Array<Promise>, Function) => Promise
Waits for all of the promises in an array to be fulfilled and
applies the resolved values to a function. Returns a promise for
this value.
combinators
qall
includes boolean logic combinators which operate on promises:
qall.some : (...terms : Promise<Boolean>) => Promise<Boolean>
qall.every : (...terms : Promise<Boolean>) => Promise<Boolean>
qall.not : (term : Promise<Boolean>) => Promise<Boolean>
For explicit ordering control, for use with Lazy Promises:
qall.someSerial : (...terms : Promise<Boolean>) => Promise<Boolean>
qall.everySerial : (...terms : Promise<Boolean>) => Promise<Boolean>
Array utils
qall.map : (Array<T>|Promise<Array<T>>, (T)=>T2|(T)=>Promise<T2>) => Promise<Array<T2>>
qall.filter : (Array<T>|Promise<Array<T>>, (T)=>Boolean|(T)=>Promise<Boolean>) => Promise<Array<T>>
installation
$ npm install qall
running the tests
From package root:
$ npm install
$ npm test
about the name
Although similar in name to Q.all, the behavior is actually more similar to Q.spread but with a more functionally-inspired API. It should be pronounced like "call".
Lamentably, Promises/A+ doesn't conform to Fantasy Land monads, so this implementation is necessary, rather than a generic liftN
.
contributors
- jden jason@denizac.org
license
MIT. (c) MMXIII jden jason@denizac.org. See LICENSE.md