Socket
Book a DemoInstallSign in
Socket

coroutinify

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coroutinify

generator based control flow middlware

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

Coroutinify

NPM version Build status Test coverage Downloads

Coroutinify is a simple Generator based control flow middlware package for Node.js.

It's like Bluebirds' coroutine and uses it internally. In spite of Bluebird's coroutine, it can be used not only with GeneratorFunctions but also with objects which contain GeneratorFunctions. It supports ES6 classes and Symbol keys too.

In case of object the original functions are not removed but added Gen suffix to its name.

Usage

For single function

const co = require('coroutinify');
function* generator() {
    let index = 0;
    while(index < 3)
        yield index++;
    return index;
}
co(generator)()
.then(value => console.log(value));    

For the whole object which also has Symbol keys

const co = require('coroutinify');
const Promise = require('bluebird');
let objcet = {};
object.gen1 = function* () {
    let index = 0;
    while(index < 3)
        yield index++;
    return index;
};
objcet.gen2 = function* () {
    let index = 0;
    while(index < 3)
        yield index++;
    return index;
};
objcet[Symbol.for('gen3')] = function* () {
    let index = 0;
    while(index < 3)
        yield index++;
    return index;
};
co(object);
Promise.all([
    object.gen1(),
    object.gen2(),
    objcet[Symbol.for('gen3')]()])
    .then(results => console.log(results));    

For ES6 class instances

const co = require('coroutinify');
const Promise = require('bluebird');
class ES6 {
    *gen1 () { yield 1; }
    *gen2 () { yield 2; }
    *[Symbol.for('gen3')] { yield 3; }
}

let es6Instance = new ES6();

co(es6Instance);
Promise.all([
    es6Instance.gen1(),
    es6Instance.gen2(),
    es6Instance[Symbol.for('gen3')]()])
    .then(results => console.log(results));    

License

MIT

Keywords

async

FAQs

Package last updated on 22 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts