@yoda/util

Classes

compose.Break

Methods

(inner) compose(monads, callbackopt)

Usage:

compose([
 cb => fs.readFile('/homes/foobar/file.txt', 'utf8', cb),
 (cb, data) => httpClient.post('http://example.com', { body: data }, cb)
], (err, res) => {
 ... do whatever you want
})

Also, in progress of composition, a break of rest of monads can be achieved by returning a module:@yoda/util.compose.Break

Example:

compose([
 cb => fs.readFile('/homes/foobar/file.txt', 'utf8', cb),
 (cb, data) => {
   if (condition) {
     return compose.Break(data)
   }
   ... do rest of the operations
 },
 (cb, data) => {
   ... would not be invoked if broke
 }
], (err, res) => {
 ... broken composition jumps here directly
 ... do whatever you want
})
Parameters:
Name Type Attributes Description
monads Array.<module:@yoda/util~ComposeMonad>
callback function <optional>

finale callback, if no callback is specified, result would be discarded, and error would be thrown

Type Definitions

ComposeMonad(callback, previous) → {void}

Parameters:
Name Type Description
callback function

normal arbitrary callback function

previous *

result from previous monad

Returns:
Type:
void

return value is discarded