When.js 3.4.2 发布了,该版本修复了一个 Bug:
Fix for rare false negative in unhandled rejection reporting.
When.js 是 cujojs 的轻量级的 Promises/A 和 when() 实现,从 wire.js 的异步核心和 cujojs 的 IOC 容器派生而来。包含很多其他有用的 Promiss 相关概念,例如联合多个 promiss、mapping 和减少 promises 集合以及 timed promises 等。
示例代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var when = require( 'when' );
var rest = require( 'rest' );
when.reduce(when.map(getRemoteNumberList(), times10), sum)
.done( function (result) {
console.log(result);
});
function getRemoteNumberList() {
return rest( 'http://example.com/numbers' ).then(JSON.parse);
}
function sum(x, y) { return x + y; }
function times10(x) { return x * 10; }
|
|