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
3
votes
1 answer

How to handle errors globally using co in express

I am new to nodejs and co. I am using co in express like below, since it is more like the async await I am used to in c# and I think the code is more readable. (req, res) => { co(function*(){ var book = req.book; …
dannie.f
  • 2,395
  • 2
  • 22
  • 20
3
votes
2 answers

How can I use co with express?

I'm using express with node and want to use a co/yield patter to wrangle my async callbacks. The current code looks like this: web.post('/request/path', function(req, res, next) { co(function *() { let body = req.body let…
SenseDeep
  • 3,026
  • 3
  • 17
  • 19
3
votes
0 answers

file upload with nodejs koa co-busboy

I use co-busyboy to parse file fields when uploading files using KOA. The official example looks like this: var parse = require('co-busboy') var parts = parse(this); var part; while (part = yield parts) { if(!part.length) //it is a stream …
M. Zhang
  • 41
  • 4
3
votes
0 answers

require module with promise function

I wrap my each router module like below IndexBase.js, if I want to require a module like othercrudmodule.js, and these function have to execute with promise too, I tried use co in the othercrudmodule.js too but I know absolutely not work How to…
user1575921
3
votes
3 answers

NodeJs, how to return data from co to outside object

Need help! How could I get data outside form co ? I don't want to handle them in .then(). I have some code like this (ES6): static class MyClass{ //get some data static getMyData(){ co(function *() { //get…
butaixianran
  • 301
  • 1
  • 2
  • 6
2
votes
5 answers

Confusion in the concept of constant time/space complexity

I am confused with the concept of constant time/space complexity. For example: public void recurse(int x) { if(x==0) return; else recurse(x/10); } where, 1
coder19
  • 61
  • 1
  • 6
2
votes
2 answers

Splitting Column Headers and Duplicating Row Values in Pandas Dataframe

In the example df below, I'm trying to find a way to split the column headers ('1;2','4','5;6') based on the ';' that exists and duplicate the row values in these split columns. (My actual df comes from an imported csv file so generally I have…
jwlon81
  • 339
  • 3
  • 15
2
votes
0 answers

Node async script sometimes ends unexpectedly

I have a node script that calls many processes to package up files. Most of the time, this works great, however once in a while (maybe on average 1 out of every 5 calls?) it just stops in the middle, always in the same spot. Specifically, the end…
Duffmaster33
  • 1,160
  • 9
  • 16
2
votes
1 answer

TypeScript async/await vs JS tj/co

Do I understand correctly that I do not need to use libs like tj/co in TypeScript to control flow, since I can use async/await? Using promises with generators is just a workaround for async/await?
SalientBrain
  • 2,431
  • 16
  • 18
2
votes
2 answers

Proper way to make callbacks async by wrapping them using `co`?

It is 2016, Node has had nearly full ES6 support since v4, and Promises have been around since 0.12. It's time to leave callbacks in the dust IMO. I'm working on a commander.js-based CLI util which leverages a lot of async operations - http requests…
Aksel Gresvig
  • 715
  • 1
  • 9
  • 21
2
votes
1 answer

Socket.io + co: Is this how it's supposed to be used?

I am trying to get http://socket.io/ working with co. I am trying to do some tasks asynchronously in my code. io.on('connection', function (socket) { // <--- need to do something heavy here socket.on('something', function (data) { …
basickarl
  • 37,187
  • 64
  • 214
  • 335
2
votes
1 answer

Dynamic routes in Koa?

Let's say I have an array of routes that looks like this: var routes = [ { route: '/', handler: function* () { this.body = yield render('home', template.home) } }, { route: '/about', handler: function* ()…
sundar
  • 105
  • 1
  • 8
2
votes
1 answer

How to use Bluebird promisification with generators + parallel promises

Trying to fire off mutiple requests off to the beats api using bluebird as well as koa for generators. After reading some documentation I figured the following would work var request = require('co-request'), _ = require('lodash'), Promise =…
Austin Davis
  • 3,516
  • 10
  • 27
  • 47
2
votes
1 answer

Generators - thunkifying JSON.parse returns odd results

I am trying to read a JSON file using co and generators. test.json contains: { "hello": "world" } This passes jsonlint so it should be valid. Here is my code at present: #!/usr/bin/env node --harmony var co = require('co'), fs = require('fs'), …
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
1
vote
1 answer

react-native cocoapods Error message : Looks like your iOS environment is not properly set

-When I configure the environment and run the following command npx react-native init AwesomeProject Error message An error occurred while installing json (2.6.3), and Bundler cannot continue. Make sure that `gem install json -v '2.6.3' --source…
Dev
  • 11
  • 2