プロミスの解決された値を返す関数を求めています。正常に失敗することは間違いなくおまけですが、関数が呼び出されたときに promise が解決される準備ができていることが想定された前提条件です。
以下のようなキュー操作を可能にするwebdriver.js promise 実装を使用していますが、キュー/チェーンなどのセマンティクスであまり迷子になりたくありません。達成しようとしています:
var inputs = [...], outputs;
outputs = inputs.map(function(input){
//queue some async tasks to be performed with input
queue.enqueue(...);
//I can't return the *output* value here yet, naturally, so instead
return promise;
});
//now I'll add another task to the same queue
//this means that by the time this task is run
//the async tasks above would have been executed
//and the promises would be "resolvable"... right?
queue.enqueue(function(){
console.log(outputs); //>an array of promises
console.log(doSomeMagic(outputs)); //>resolved values as needed <<<
});
NB: afaikQ.all()
は私が求めていることを実行しません。promise の配列を取り、解決された valueではなく、配列の promise を返します。私は間違っていることが証明されてうれしいです。