potem
Modern, very fast, lightweight, async, promise-like class
Learn from the examples:) You can find many of them in the spec/
directory.
Version 3
Version 3 is not compatible with version 1.x nor with 2.x.
Potem class has been converted to "potem" function.
Now you are able to then
functions without "then" keyword because potem
function
returns itself.
install
npm install potem
sync usage
var potem = potem;var result = 0; { return n + 1;} { return n * 2;} { result = n;};
Basic async example
var potem = potemvar fs = ; var p = ;
Basic async example using argument converters
var potem = potem;var fs = ; var p = ;
async usage (read directory content)
var potem = potem;var fs = ; var p = potem ;
more examples
For more examples check out the spec/ directory
API
.then(callback:(...args))
add callback
function to the call stack. Take last returned argument as an input. Or if the execution was paused take last resume()
(resume is returned from .pause()) function arguments as its own arguments.
.then([...callbacks:(..arrOfArgs)[]])
In this case (if array of callbacks are arguments) every callback will be called with all the arguments that ware passed to resume()
function (or last return statement)
for example:
var potem = potem;var fs = ; var p = potem ;
.error(errCallback:(err))
Set the error handler. If any of "then" functions thew an error then this function will be called.
If an error will be called in this function then it can be cought in the next .error()
of .fin()
function.
.fin(callback:(...args))
It's like .then()
but will be called even if an error was thrown.
.pause(pauseCounter:number, ...argumentConverters)
Returns the resume()
function and pauses the execution. If you specify the pauseCounter
parameter then the execution will be paused for pauseCounter
number of times (resume()
function would have to be called pauseCounter
times for the next .then()
to be called).
You can specify any number of argument converters. Argument converters do something with the arguments and after the conversion they pass the result to the next .then()
function.
.stdPause(pauseCounter:number)
Shorthand for .pause(pauseCounter, p.throwArg);
for callbacks with standard (usually node) call signature.
.passArg argument converter
This argument converter does nothing. It's usefull if you want to do something with arguments that are passed on the later positions.
var potem = potem; var { ;} var p = potem
.skipArg argument converter
Removes the argument on the current position from the argument set
var potem = potem; var { ;} var p =
.throwArg argument converter
Throws an error if a argument if truthy.
var potem = potem; var { ;} var p =
This argument converter is especially useful when working with nodejs.
var p = ;
In nodejs it is very common that we have this callback signature:
So we usually would use pause
like this: p.pause(1, p.throwArg)
.
For this reason there is a helper method added: p.stdPause()
that
is equivalent with p.pause(1, p.throwArg)
.
Plans for a next version???
Warning not implemented yet!
Here is a draft of what is comming to be a part of v4.0:
var files = ;var seq = ;