1.0.1 • Published 7 years ago
@buzuli/seq v1.0.1
@buzuli/seq
Perform a sequence of asynchronous actions, one per line, indicating outcome, duration, and custom message pre/post.
API
The api exports an init() function which creates a new sequencer.
The sequencer function (typically aliased seq) is used for each action.
init(options)
options:
rethrow:boolean=true- rethrow action errors (can override per action)stream:stream.Readable=process.stdout- the stream to which the output of actions should be written.
Returns a new sequencer function.
seq(prefix, action, [suffix, [options]])
params:
prefix:string | => string- prefix text or supplieraction:function | Promise- the action to be awaitedsuffix:string | ({duration, result, failure}) => string- suffix text supplieroptions.rethrow:boolean- override the global rethrow config
Returns a Promise supplying the result of the action.
Example
const seq = require('@buzuli/seq')({
stream: myStream // Custom output stream [defaults to process.stdout
})
const sleep = d => new Promise(r => setTimeout(r, d))
await seq("Sleeping", () => sleep(500), "Rested")
await seq("Working", () => { /* Not really */ }, "Feeling accomplished")