【发布时间】:2016-09-23 14:21:53
【问题描述】:
我遇到了 highland.js 的问题。我需要从我的流数据中创建一个函数数组,但不能让它工作。这是我的代码,但requests 始终为空。
var requests = [];
_(fs.createReadStream("small.txt", { encoding: 'utf8' }))
.splitBy('-----BEGIN-----\n')
.splitBy('\n-----END-----\n')
.filter(chunk => chunk !== '')
.each(function (x) {
requests.push(function (next) {
Helpers.Authenticate()
.then(function (response1) {
return Helpers.Retrieve();
})
.then(function (response2) {
return Helpers.Retrieve();
})
.then(function () {
next();
});
});
});
console.log(requests)
async.series(requests);
【问题讨论】:
-
我刚刚重新阅读了您的问题。介意告诉我们
async.series(requests)做了什么吗?但总的来说,如果您希望console.log上面的行看到async.series上的请求,那么它当然会返回空的,因为流不会像异步一样阻塞。 -
这是 async.js (caolan.github.io/async/docs.html#.series) 库
-
我明白了。因此,这与您面临的问题无关。您可能需要为流创建一个承诺或传递一个回调以完成填充
requests,然后将console.log输出或对其执行async.series。 -
.each 是一个 jQuery 函数。如果您使用 forEach,则不使用 X 参数。
-
@manuerumx 它也是
highlandjs中的一个函数。
标签: javascript node.js highland.js