Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including yielded with all npm packages installed. Try it out:

var yielded = require("yielded")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

yielded v0.3.1

Another generator runner

yielded

Another generator runner

yielded doesn't help you with callback generator, it uses promises. To convert a function with a callback to a promise, you can use springbokjs-utils promiseCallback.

Installation

npm install --save yielded

How to use

var Y = require('yielded');
var fs = require('springbokjs-utils/fs');

Y.run(function* () {
    try {
        var fileContents = yield fs.readFile('./myFile.json');
        console.log(JSON.parse(fileContents));
    } catch (err) {
        console.error(err);
    }
});

Parallel executions

With arrays

You can use arrays with values and promises:

Y.run(function* () {
    var result = yield [
        1,
        2,
        new Promise(function(resolve, reject) {
            setTimeout(function() {
                resolve(3);
            });
        }),
        new Promise(function(resolve, reject) {
            resolve(4);
        }),
    ];
    console.log(result);
    // [1, 2, 3, 4]
});

Iterator inside

var Y = require('yielded');
var fs = require('springbokjs-utils/fs');

var readFileContents = function* () {
    try {
        var fileContents = yield fs.readFile('./myFile.json');
        console.log(JSON.parse(fileContents));
    } catch (err) {
        console.error(err);
    }
};

Y.run(function* () {
    var result = yield readFileContents();
    console.log(result);
});

Credits

This library is an attempt to understand generators and yields, the result of my research of other libraries and taking the parts I like from them. Libraries I took inspiration from are:

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free