这个例子混淆了我对工作原理的理解node.js:
// 1.
numbers.forEach(function(number) {
queue.push(Q.call(slowFunction, this, number));
});
// 2.
// Q.all: execute an array of 'promises' and 'then' call either a resolve
// callback (fulfilled promises) or reject callback (rejected promises)
Q.all(queue).then(function(ful) {
// All the results from Q.all are on the argument as an array
console.log('fulfilled', ful);
}, function(rej) {
// The first rejected (error thrown) will be here only
console.log('rejected', rej);
}).fail(function(err) {
// If something went wrong, then we catch it here, usually when there is no
// rejected callback.
console.log('fail', err);
}).fin(function() {
// Finally statement; executed no matter of the above results
console.log('finally');
});
为什么在这里假设部分代码将按顺序执行1.?那么,适用于所有推入元素2.的保证在哪里?是不是这样,from是如此之大,以至于它的工作原理比平行于?这些想法来自对 node.js 将处理的理解,首先是使用然后将其交给,这实际上类似于普通线程。Q.all(queue)queue1.numbers1.2.1.2.node.js event-loopworkers
所以问题 - 将彼此1.并行2.执行,从node.js event-loop顺序开始还是按顺序执行(1.推送队列中的所有元素,然后才2.开始处理中的每个元素queue)?请提供一些指向该主题文档的直接链接的论点。