1.0.1 • Published 6 years ago

@buzuli/seq v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

@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 supplier
  • action: function | Promise - the action to be awaited
  • suffix: string | ({duration, result, failure}) => string - suffix text supplier
  • options.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")
1.0.1

6 years ago

1.0.0

6 years ago