Coder Social home page Coder Social logo

roads-coroutine's Introduction

Async and Await are in stable versions of node! Use that instead!

roads-coroutine

A simple library to turn javascript generators into promise-returning functions.

Examples

var cr = require('roads-coroutine');

var fn = cr(function* (param) {
  var result = yield promiseReturningAsyncFunction(param);
  return "final result: " + result;
});

fn('hey!').then(function (response) {
  console.log(response);
}, function (err) {
  console.log(response);
});

The tests have even more examples!

Warning

There are versions of iojs pre-2.5.0 that can generate false "unhandled rejection" events. Please make sure you are using at least 2.5.0

roads-coroutine's People

Contributors

dashron avatar derhuerst avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

roads-coroutine's Issues

False unhandled rejection

Creating issue for future reference. In certain versions of iojs the following code throws an unhandled rejection error

"use strict";

process.on('unhandledRejection', function(reason, p) {
    console.log("\nUnhandled Rejection at:\n Promise ", p, "\n reason: ", reason);
    throw reason;
});

var coroutine = require('./index.js');

var first = coroutine(function* () {
    yield new Promise(function (resolve, reject) {
        resolve(null);
    });

    return new Promise(function (resolve, reject) {
        reject(new Error('Unauthorized'));
    });
});

first()
.then(function (response) {
    console.log('resp', response);
}, function (err) {
    console.log('err', err);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.