result-co

1.0.0 • Public • Published

result-co

Turn a generator function back into a normal one but where any yielded values are awaited before continuing. Promises, thunks, etc.. get you closer to blocking semantics but often the syntax they require obscures that. This helps get your syntax even closer to the blocking version.

Installation

With your favorite package manager:

  • packin: packin add result-co
  • component: component install jkroso/result-co
  • npm: npm install result-co

then in your app:

var co = require('result-co')

API

co(generator)

co takes a generator function and returns a normal one. Except it will have the special ability to unwrap/await results by yielding them.

var Result = require('result')
var wrap = Result.wrap
var add = co(function*(a, b){
  return (yield a) + (yield b)
})
add(1,2) // => 3
add(wrap(1), 2) // => 3
var one = new Result
var three = add(one, 2)
three // => new Result
one.write(1)
three // => wrap(3)
add(three, three) // => 6

Readme

Keywords

Package Sidebar

Install

npm i result-co

Weekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jkroso