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

how to use co with a named function?

So I am trying to use co to wrap around MongoDB methods that return promises eg http://mongodb.github.io/node-mongodb-native/2.0/reference/ecmascript6/crud/ I see co being used like: co(function*() { which seems like an anonymous function. Fine in…
dcsan
  • 7,487
  • 10
  • 50
  • 80
0
votes
1 answer

Koa.js yield value with a race condition

I have an app that uses koa.js, and for context I am in the process of interfacing an external system that doesn't strictly follow request/responses pattern. IE. after a "request", it may or may not answer. I am able to match my requests to these…
nha
  • 16,039
  • 11
  • 76
  • 108
0
votes
1 answer

Mocha with co.wrap with generator arrow functions

I took an existing test: it('should have a controller instance', co.wrap(function *() { stateController.should.be.a('object'); })); and tried to use arrow syntax on the generator function and it the runtime complains it('should have a…
PositiveGuy
  • 11,583
  • 13
  • 50
  • 102
0
votes
1 answer

mongoose doesn't resolve queries

I'm struggling to understand what's wrong with the following queries. I'm using the mongoose 4.1.10 and mongodb 3.0.6. passport.use("local-signup", new passportLocal.Strategy({ // by default, local strategy uses username and password, we will…
ppoliani
  • 4,266
  • 2
  • 30
  • 58
0
votes
1 answer

Co and co.wrap behave differently in Node.js

Although I kind of figured out how the Koa flow mechanims work (I think), I can't seem to grasp all of the differences between co and co.wrap. This is the code that is giving the unexpected behavior: "use strict"; var co = require("co"); function…
Michele De Pascalis
  • 840
  • 1
  • 9
  • 26
0
votes
2 answers

Exiting Final Promise Scope from Within a Generator Function

I'm having trouble trying to return promise results as a yield back to the original caller. store.js module.exports = { find: function *(storeRequest){ if(!_gateway){ _gateway = realGateway; } …
PositiveGuy
  • 11,583
  • 13
  • 50
  • 102
0
votes
1 answer

co.wrap yield Promise throw TypeError: undefined is not a function

I yleld a Promises in co.wrap, but it throw TypeError: undefined is not a function (the error line is yield pm2.connect();) app.js: var app = koa(); app.init = co.wrap(function *(overwriteDB) { yield pm2.connect(); koaConfig(app); …
zwb
  • 679
  • 1
  • 6
  • 16
0
votes
2 answers

Using mocha+chai together with co

When chai.expect assertions fail, they normally fail the test and the negative result gets added to the report for the test runner (in this case mocha). However, when I use a generator function wrapped using co.wrap(), as seen below, something…
bguiz
  • 22,661
  • 40
  • 140
  • 226
0
votes
0 answers

is there a way to create a instance

Since from co@4.0+ we can use below statement var fn = co.wrap(fn*) to convert a generator into a regular function that returns a Promise. Then I face a problem a.js var F = function *(a,b,c){ this.a = yield this.getA(a); this.b = yield…
pigcan
  • 83
  • 1
  • 1
  • 6
0
votes
0 answers

Avoiding callback hell using generators and promises (Co module)

I am new to nodejs. Here, I want to avoid callback using Co generators with promises. But when I execute this code, it only executes first yield or does not assign the result of get function to processedData0 variable. How to solve this…
0
votes
2 answers

Using supertest and co to validate database content after request

I want to write a test to update a blog post (or whatever): * Insert a blog post in a database * Get the id the blog post got in MongoDb * POST an updated version to my endpoint * After the request have finished: check in the database that update…
Marcus Hammarberg
  • 4,602
  • 1
  • 28
  • 36
0
votes
1 answer

How can I emulate a synchronous call with generators in javascript?

Suppose the next piece of code: var co = require('co'); var myObj = { getFieldValue: function() { var self = this; console.log(JSON.stringify(self)); if (!self.fieldValue) { return function(cb) { …
jbaylina
  • 3,878
  • 1
  • 25
  • 37
0
votes
1 answer

How to instantiate an object whose constructor uses yield?

I have a helper constructor that uses a yield statement: var co = require('co'); var Helper = co(function* () { var response = yield foo(); }) module.exports.Helper = Helper; I would like to instantiate it: var Helper =…
Felix
  • 2,817
  • 5
  • 29
  • 45
0
votes
3 answers

Remove entire column with same strings (with header remains) using grep or awk

I have a file as below: name1 name2 name3 name4 AA BB BB CC AA AA BB CC AA CC BB CC AA DD BB DD AA DD BB AA column 1 and column 3 have the same string within itself. I wish to remove the entire column if the…
bison72
  • 183
  • 1
  • 12
0
votes
0 answers

Using node.js / express / yields / co / postgres do we connect to database on every client connection?

I am wondering if when running pg-co with node express server, do you connect to the database on every client connection? or keep a global connection? Reference: https://github.com/basicdays/co-pg In other words, here is my node…
born2net
  • 20,205
  • 21
  • 54
  • 94