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 gensync with all npm packages installed. Try it out:

var gensync = require("gensync")

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

gensync v0.1.0

Async-Await for the modern Node

GenSync

Async-Await for the modern Node, using generators!

'use strict';

const A = require('gensync');

const resolvedPromise = () => Promise.resolve(5);
const rejectedPromise = () => Promise.reject(5);


const add = A.sync(function* (a, b) {
    let val = yield A.wait(resolvedPromise());
    try {
        val += a + b;
        val += yield A.wait(rejectedPromise());
    } catch (err) {
        if (err === 5) {
            val -= err;
        } else {
            val = 'meow';
        }
    }
    return val;
});

const main = A.sync(function* () {
    console.log(yield A.wait(add(2, 7)));
});

main(); // 9

Metadata

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