Coder Social home page Coder Social logo

generator-async's People

Contributors

dchester avatar dweinstein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

generator-async's Issues

iojs - Unexpected token ILLEGAL

% iojs --harmony -e 'var async = require("generator-async"); var fs = async.require("fs");'
/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:3718
            throw e;
                  ^
Error: Line 26: Unexpected token ILLEGAL
    at throwError (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:1836:21)
    at scanNumericLiteral (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:900:13)
    at advance (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:1311:20)
    at lex (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:1360:78)
    at expect (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:1896:21)
    at parseArguments (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:2217:17)
    at parseLeftHandSideExpressionAllowCall (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:2283:24)
    at parsePostfixExpression (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:2325:16)
    at parseUnaryExpression (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:2352:20)
    at parseBinaryExpression (/Users/user/junk/generator-async/node_modules/generator-async/node_modules/module-async-mapper/node_modules/esprima/esprima.js:2473:16)

How to use parallel

I'm getting an error when trying to call my own function with async.parallel:

var async, get, request;
async = require('generator-async');
request = async.require('request');

get = async(function*(url) {
  var data;
  data = (yield request(url));
  return data;
});
// this works.
async.run(function*() {
  var data;
  data = (yield get("https://www.google.com/"));
  console.log(data["statusCode"]);
  data = (yield get("https://www.yahoo.com/"));
  console.log(data["statusCode"]);
});
// this gives error: Error: Attempted to yield bad value: _async_yield
async.run(function*() {
  var data1, data2;
  async.parallel(get("https://www.google.com/"));
  async.parallel(get("https://www.yahoo.com/"));
  data1 = (yield async["yield"]);
  data2 = (yield async["yield"]);
});

coffeescript version:

async = require('generator-async')
request = async.require('request')

get = async (url) ->
 data = yield request(url)
 return data

# this works
async.run ->
  data = yield get("https://www.google.com/")
  console.log data["statusCode"]
  data = yield get("https://www.yahoo.com/")
  console.log data["statusCode"]
  return

# this gives error:
# Error: Attempted to yield bad value: _async_yield  
async.run ->

  async.parallel(get("https://www.google.com/"))
  async.parallel(get("https://www.yahoo.com/"))
  data1 = yield async.yield
  data2 = yield async.yield

  return

What am I doing wrong?

"use strict" bricks the library

I tried the introductory example like this:

var async = require('generator-async');
var fs = async.require('fs');

async.run(function*(){
    "use strict";

    // read a file
    var passwd = yield fs.readFile('/etc/passwd');

    // then read another file
    var group = yield fs.readFile('/etc/group');

    // then spit out the contents of both files
    console.log(passwd, group);
});

Results in error: Error: Attempted to yield bad value: undefined

I guess the problem is, that fs.readFile() does not return promises.

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.