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

我的梦境 提交于 2019-12-04 15:45:06

Simplest thing to do might be to wrap getModelPromise so that it returns a promise resolving to an object with your model and your data as properties instead of just your model.

Or, if you don't want to use a promise you can do it in Highland:

var modelStream = eventStream.map(function (data) {
    return _(getModelPromise(data.id)).map(function (model) {
        return {data: data, model: model};
    });
}).parallel(10);

// then...
modelStream.map(function (x) {
    x.model.doStuff(x.data.foo);
});

Zipping the modelStream and an observed version of the eventStream should also work, but I usually prefer to pass around objects which contain everything you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!