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
0 answers

Issue with mkdirp from fs-promise and co

I have a generator function that creates a directory and performs operations on it once done: import co from 'co' import map from 'lodash/fp/map' import path from 'path' import {mkdirp} from 'fs-promise' import co from 'co' export const…
vamsiampolu
  • 5,355
  • 15
  • 65
  • 161
0
votes
1 answer

Loosing parameters passed from co-wrapped function to another one

I'm using the latest co-module (4.6). This is a Koa-middleware. Therefore it is already co() wrapped. create: function * () { try { this.body = yield services.createIt({obj: true}) } catch (err) { this.body = { "errors": err.details } …
Hedge
  • 13,498
  • 35
  • 122
  • 223
0
votes
1 answer

Advantages of using co over async/await functions and compiling with babel

Co bills itself as a "stepping stone towards ES7 async/await", but I'm not really sure why I should use it over just writing async functions and using babel to compile. Are there any advantages and disadvantages to these approaches or is it just a…
0
votes
1 answer

jshint logs missing semicolon after yield in co

I am using JSHint for linting and have encountered a problem when using co, within generator in yield statement I get ERROR: line 18 col 28 Missing semicolon. co(function *() { let orgAccounts = yield OrgAccount.findAll({accountId:…
0
votes
1 answer

Mongoose doesn't yield findeOne results in co

I'm using co and mongoose and I'd like to my asynchronous code look little more "synchronously" and - as far as I read - co library allows me use data from one yielded promise in another to avoid callback hell. It seems to work with mongoose save…
Jarosław Rewers
  • 992
  • 2
  • 11
  • 23
0
votes
1 answer

How do a I terminate a co.js loop after execution?

Whenever I run a co generator loop, nothing happens after execution the process just hangs. How do I terminate after completion? co(function *() { // code; })
user157251
  • 64,489
  • 38
  • 208
  • 350
0
votes
1 answer

silent errors in mocha tests with generator functions

I want to unit test a function. In that function I'm using Co with a generator function. When an error occurs I catch it, and I call cb with the error In my unit test I make a false assertion but mocha doesn't report it, it just times…
Ernie
  • 922
  • 1
  • 10
  • 22
0
votes
2 answers

Javascript.Run Multi promises Synchronously

I want to request a website for 40 times. I want this to be synchronously, like 10 requests 4 times. This is My code for 1 request - 40 times: 'use strict'; var request = require('request'); var co = require('co'); function callUrl(url) { …
Catalin
  • 248
  • 2
  • 12
0
votes
1 answer

Codeigniter Array Display

I want to display values of an array, but it only displays one value of the array rather than all values of the array. Model: function get_subject_position($exam_id , $class_id , $subject_id ) { $this->db->where('exam_id' , $exam_id); …
4Jean
  • 737
  • 1
  • 11
  • 24
0
votes
1 answer

Proper way to create a co-sqlite3 db object outside of a middleware

I am trying to implement a db access layer within my koa application. This works fine: var sqlite3 = require('co-sqlite3'); var services = require('./services/services'); app.use(function *(next){ this.db = yield sqlite3(services.file); …
0
votes
1 answer

Can't find an explanation for koa.js workshop solution, exercise number one

It has to be rather simple, but I can't understand the solution for the beginning exercise from koa workshop. The test: var co = require('co'); var assert = require('assert'); var fs = require('./index.js'); describe('.stats()', function () { …
Georgy
  • 2,002
  • 2
  • 17
  • 31
0
votes
1 answer

catch reject from promise

I want to hold the error from func() reject, not direct to onError() by choise, Before I always let func() resolve, and determine return result after yield func(), if I want to direct to onError() use throw ..; Wondering any better idea I can just…
user1575921
  • 948
  • 1
  • 14
  • 26
0
votes
1 answer

Javascript - Using generators instead of promises

suppose I have following functions: var f1 = function() { console.log('running f1'); return new Promise(function(res, rej) { setTimeout(() => res('resolved_1!'), 1000); }); }; var f2 = function(a) { console.log('running f2…
Javad M. Amiri
  • 424
  • 4
  • 14
0
votes
3 answers

NodeJS generator never reaches a certain line?

I am using co to run a generator function that does some scraping and cleansing of data. However, I never reach a certain part of the code after a loop. Here's what my code looks like: function*(){ var url = "mongodb://" + config.host + ":" +…
An SO User
  • 23,378
  • 30
  • 119
  • 197
0
votes
1 answer

using co and promises from sync code (mongoDB example)

How do I use co() wrapped functions to integrate with normal synchronous code? For example I have co.wrapped this function that uses yield to call an async method on mongo: let wrap = co.wrap(function* (collName) { debug("collName", collName); …
dcsan
  • 7,487
  • 10
  • 50
  • 80