dchester / generator-async Goto Github PK
View Code? Open in Web Editor NEWFlexible generator-based asynchronous control flow for Node.js.
License: MIT License
Flexible generator-based asynchronous control flow for Node.js.
License: MIT License
% 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)
Has it not been implemented yet?
async.forEachLimit(data, 1, function*(acct) {
}
TypeError: async.forEachLimit is not a function
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?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.