Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

so

Artazor256MIT1.0.1

So, the most straightforward coroutine library for everyday use

so, async, await, yield, coroutine, generators, harmony, promise

readme

So

NPM version build status Test coverage

The most straightforward co-routine library for Node.JS ever. Provides predictable composable async/await from C#5.0 style co-routines for everyday use since you can live in a Harmony.

Inspired by @ForbesLindesay's great presentation: http://pag.forbeslindesay.co.uk/#/ and @visionmedia co. As of co-4.0 that was rewritten to use promises, so-1.0 can be compared with co.wrap and represents its more light and strict version.

Platform Compatibility

When using node 0.11.x or greater, you must use the --harmony-generators flag or just --harmony to get access to generators.

When using node 0.10.x and lower or browsers without generator support, you must use gnode and/or regenerator.

Also as of so-1.0 you should ensure existence of Promise either by using --harmony or any available polyfill.

Installation

$ npm install so

Usage


var so = require('so');
var fs = require('then-fs');

var readJSON = so(function*(path){
  return JSON.parse(yield fs.readFile(path, 'utf8'));
});

var main = so(function*(){
  var a = yield readJSON('a.json');
  var b = yield readJSON('b.json');
  console.log({a:a, b:b});
});

main().catch(function(e){
  console.log(e.stack || e.message || e);
});

or for CoffeeScript

so = require 'so'
fs = require 'then-fs'

readJSON = so (path) ->
  JSON.parse yield fs.readFile path, 'utf8'

main = so ->
  a = yield readJSON 'a.json'
  b = yield readJSON 'b.json'
  console.log {a, b}

main().catch (e) ->
  console.log e.stack ? e.message ? e