プロミス ハンドラーは、いくつかの主要な promise ライブラリ ( Q、When、Bluebird ) で廃止され、新しいPromises/A+ 仕様からも削除されました。プログレス イベントを廃止する理由は理解できますが、慣れ親しんだ次のパターンをリファクタリングするのに苦労しています。
var download = function(url) {
var deferred = Q.defer();
...
http.get(url, function(res) {
res.on('data', function(chunk) {
data += chunk.toString();
deferred.notify('Downloading: ' + (data.length / totalLength) + '%');
/* ^Notify download progress, but progress events are now deprecated :( */
});
res.on('end', function() {
deferred.resolve('Success: ' + url);
});
res.on('error', function(err) {
deferred.reject(err);
});
});
return deferred.promise;
}
...
download(url).then(console.log, console.log, console.log);
/* ^The third handler keeps logging progress, but this is now deprecated :( */
コードのリファクタリングの例が Web のいたるところに出てくるのを見てきましたが、これらすべての例では、進行状況の更新の数が事前にわかっているようです。上記のパターンでは、発行される進行状況の更新の数は無期限です。
プログレスイベント/ハンドラーを使用せずに上記のパターンを実装するのを手伝ってくれる人はいますか?