Limp
Limp is a simple asynchronous control-flow library. It is meant to be a mostly drop-in replacement for the step library, and so has a very similar API. Why use it instead of step? While step is a useful library, Limp improves upon it in several ways.
-
Limp removes the synchronous behaviors. This is important, because accidentally returning a value in step was an easy way to accidentally advance to the next stage when asynchronous tasks were still running.
-
Limp throws exceptions when used incorrectly. This makes debugging incorrect usage of the library easier. Step would often keep running, but with hard-to-predict behaviors.
-
Adds several new features, such as
this.await()
for promise support, andthis.rest()
for multi-argument support in combination with other callback types.
Overview
The idea of Limp is that code is organized in 'stages', which are just functions. We advance from a stage when all callbacks (created by Limp) have been called. Values are then assembled, and passed to the next stage.
var limp = ; { ;}
Features
Features are provided through the this
variable, which is injected into each stage function. Limp gives you callbacks with many different useful behaviors.
this
The this
variable is a function that can be used as a callback for simple cases. It will pass all arguments it receives into the next stage. You shouldn't use this
as a callback with any of the other callback types. Try using this.rest()
if you'd like that kind of behavior.
;
this.parallel()
The this.parallel()
method will manufacture a new callback for you to use. Each one of these callbacks will take both the error and the first argument that it is called with, and pass them to the next stage. Multiple this.parallel()
callbacks can be created, and each one will remember its placement relative to the others.
;
this.group()
The this.group()
method will create a factory function, that will itself produce new callbacks for you to use. Each callback created by a single this.group()
function will be passed to the next stage in an array.
;
this.await(p)
The this.await(p)
method waits for a promise. If it resolves to a value, that value is passed along to the next stage. If it rejects, the error will be passed along to the next stage, and a new error will be created if the promise rejected for no reason. This lets you easily merge promises into callback logic.
;
this.rest()
The this.rest()
method will create a callback that takes all arguments passed to it, and passes them to the next stage at the end of the argument list. This lets you mix the multi-argument behavior of the this
callback with other callback types. A this.rest()
callback should the last callback used in that stage.
;
this.errors
When a callback receives an error, that error is passed to the following stage as the first argument. If multiple callbacks error out, only the first one is passed as the first argument. If you want to see all errors, those are available in the this.errors
array. This array has the same ordering as the arguments.
;