highland.js

Using highland.js to perform async tasks in series with references to original stream data

六月ゝ 毕业季﹏ 提交于 2020-01-13 05:55:09
问题 I have a stream of events: var eventStream = _([{ id: 1, foo: 'bar' }, { id: 2, foo: 'baz' }]); For each event in the stream I need to load an instance of a model (my DAL returns promises) and then call a method on each instance of the model, passing some data from the original event data as an argument. Loading instances of the model was not too difficult: eventStream.map(function(data) { return getModelPromise(data.id); }).map(_).merge(); // result is a stream of model instances But once I

mocha with nodejs assert hangs/timeouts for assert(false) instead of error

我的未来我决定 提交于 2019-12-19 17:46:48
问题 I have this kind of a mocha test: describe 'sabah', → beforeEach → @sabahStrategy = _.filter(@strats, { name: 'sabah2' })[0] .strat it 'article list should be populated', (done) → @timeout 10000 strat = new @sabahStrategy() articles = strat.getArticleStream('barlas') articles.take(2).toArray( (result)→ _.each(result, (articleList) → // I make the assertions here // assert(false) assert(articleList.length > 1) ) done() ) The problem is, whenever I do assert(false) , the test hangs until the

mocha with nodejs assert hangs/timeouts for assert(false) instead of error

一世执手 提交于 2019-12-19 17:46:04
问题 I have this kind of a mocha test: describe 'sabah', → beforeEach → @sabahStrategy = _.filter(@strats, { name: 'sabah2' })[0] .strat it 'article list should be populated', (done) → @timeout 10000 strat = new @sabahStrategy() articles = strat.getArticleStream('barlas') articles.take(2).toArray( (result)→ _.each(result, (articleList) → // I make the assertions here // assert(false) assert(articleList.length > 1) ) done() ) The problem is, whenever I do assert(false) , the test hangs until the

Nested stream operations in Highland.js

泄露秘密 提交于 2019-12-11 12:36:12
问题 I have a stream of directories from the readdirp module. I want to:- search for a file using a regex (e.g. README.* ) in each directory read the first line of that file that does not start with a # print out each directory and this first non-heading line of the README in the directory. I am trying to do this using streams and highland.js. I am stuck trying to process a stream of all files inside each directory. h = require 'highland' dirStream = readdirp root: root, depth: 0, entryType:

Using highland.js to perform async tasks in series with references to original stream data

我的梦境 提交于 2019-12-04 15:45:06
I have a stream of events: var eventStream = _([{ id: 1, foo: 'bar' }, { id: 2, foo: 'baz' }]); For each event in the stream I need to load an instance of a model (my DAL returns promises) and then call a method on each instance of the model, passing some data from the original event data as an argument. Loading instances of the model was not too difficult: eventStream.map(function(data) { return getModelPromise(data.id); }).map(_).merge(); // result is a stream of model instances But once I have the model, I can't figure out how to invoke a method on the model and pass data.foo to it.

How to process huge array of objects in nodejs

谁说我不能喝 提交于 2019-12-01 13:32:48
问题 I want to process array of length around 100 000, without putting too much load on CPU. I researched about streams and stumbled upon highlandjs, but i am unable to make it work. I also tried using promises and processing in chunks but still it is putting very much load on CPU, program can be slow if needed but should not put load on CPU 回答1: With node.js which runs your Javascript as single threaded, if you want your server to be maximally responsive to incoming requests, then you need to