Questions tagged [co]

The Co javascript library for generator based flow-control of asynchronous tasks

Co is a javascript library for executing generators that yield asynchronous tasks, so that asynchronous code can be written in a more concise manner.

114 questions
18
votes
1 answer

How to Pipe Response to a File in Co-Request module & NodeJs?

I am using Co-Request to read Zip file from http url, and i have below code to read from server.. The code works already. But I dont know how to write the response Zip to a file. var co = require( "co" ); var request = require( "co-request" ); …
amaz
  • 345
  • 1
  • 4
  • 14
18
votes
3 answers

Any way to exports a generator function?

An example generator.js: exports.read = function *(){ var a = yield read('co.github.js'); var b = yield read('co.recevier.js'); var c = yield read('co.yield.js'); console.log([a,b,c]); } function read(file) { return function(fn){ …
Tinple
  • 1,131
  • 1
  • 10
  • 11
16
votes
1 answer

nodejs child_process.spawnSync or child_process.spawn wrapped in yieldable generator which returns output

since a while i am trying to reach something that doesn't work out for me so far. With nodejs, i like to run a interactive sh-command and work with the sh-command output after the command has exited. i like to write a yieldable generator-function…
divramod
  • 1,284
  • 2
  • 16
  • 33
14
votes
1 answer

how to start global npm module with harmony flag

I wrote a npm module which can be installed globally dm-npm. I like to use co in that module. How can i told the module that it runs with the harmony flag when started globally? Here is the package.json: { "name": "dm-npm", "version": "0.0.3", …
divramod
  • 1,284
  • 2
  • 16
  • 33
11
votes
2 answers

Getting a promise's value via yield & co

I'm trying to figure out how to get the value of a promise via yield, possibly with "co": function *(){ var someVar = yield functionThatReturnsAPromise(); } The called function is not a generator, just a normal function. With the above,…
Mark Kahn
  • 81,115
  • 25
  • 161
  • 212
8
votes
3 answers

How to perform an async task against es6 generators in loop

I understand how to use generators to make async code look nice. I have a simple generator *all, that takes a page, will return a single value. Then I have another generator *allDo, that will use *all for pages 1 to 30 and for each result, do some…
eguneys
  • 5,048
  • 7
  • 24
  • 47
6
votes
2 answers

Co.js and bluebird.js -- what's the difference?

Could someone help me understand the differences between using Koa.js and Bluebird.js with ES6 Harmony. Specifically, how does co( function * () { //stuff } ); compare to, Promise.coroutine( function * () { //stuff } ); It just seems Koa…
user157251
  • 64,489
  • 38
  • 208
  • 350
5
votes
2 answers

Understanding code flow with yield/generators

I've read over several examples of code using JavaScript generators such as this one. The simplest generator-using block I can come up with is something like: function read(path) { return function (done) { fs.readFile(path, "file",…
Explosion Pills
  • 176,581
  • 46
  • 285
  • 363
4
votes
2 answers

React.js render json response, co fetch or axios

I've been pulling my hair out too long and I can't focus anymore. I am trying to take the json from a url and just render it visually in the browser. It doesn't even need to be formatted, at least it doesn't until I get past this hurdle. I can get…
fearofmusic
  • 155
  • 1
  • 1
  • 9
4
votes
0 answers

Collection-repeat is cutting the last item

I have a collection-repeat like this (see the code below) and works fine, but the last item does not show well when the user scroll down. Why could resolve this?
4
votes
2 answers

Nodejs program doesn't terminate

This program will not terminate in the console, I have to use Ctrl-C. Documentation does not give any clues. Tried various things such as Return but just can't get it to terminate, it just hangs in the console. The last thing in the console is 'now…
Nepomuk
  • 55
  • 5
4
votes
1 answer

Difference between co and await

I'm not really understanding the difference between this code: co(function *() { const val = yield aPromise(); return val; }) .then((val) => doSomethingWith(val), (err) => doSomethingWith(err)); and this other one: async function () { …
David
  • 2,511
  • 14
  • 23
4
votes
1 answer

Does _.find return a reference to the object? How to properly set a property of the result?

I use lodash find to query object from array, then I set the property of that object but when I print out the array after setting this property, it is unchanged. I would be grateful for some comments from someone more experienced on handling objects…
Marek
  • 1,126
  • 2
  • 14
  • 30
4
votes
2 answers

Bluebird instead of Co in Koa?

Seems like Bluebird overlaps Co in generator/coroutine related functionality. Bluebird is espoused to have exceptional speed-performance, so for discussion sake, (assuming the aforementioned overlap premise is true) if one wanted to substitute…
JLS
  • 681
  • 1
  • 6
  • 10
3
votes
2 answers

delay before co() finished

I try make some node script with co. It works well, but a have big delay before script finished. (I got "Ok" or "Bad" after one second, but script finishes 7 seconds after it). What I missed? co(function *() { let errors = yield…
Stepan Loginov
  • 1,497
  • 4
  • 17
  • 40
1
2 3 4 5 6 7 8