-
Notifications
You must be signed in to change notification settings - Fork 4
/
promise-test.js
43 lines (33 loc) · 997 Bytes
/
promise-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var nodePromise = require('node-promise');
var Promise = nodePromise.Promise;
var _ = require('underscore');
// This works:
var successPromise1 = new Promise();
var errorPromise1 = new Promise();
nodePromise.allOrNone(errorPromise1, successPromise1).then(function() {
console.log('All promises resolved, should not come here');
}, function() {
console.log('One or more promises rejected, should come here');
});
_.delay(function() {
successPromise1.reject();
}, 200);
_.delay(function() {
errorPromise1.reject();
}, 201);
// This fails:
/*
var successPromise2 = new Promise();
var errorPromise2 = new Promise();
nodePromise.allOrNone(successPromise2, errorPromise2).then(function success() {
console.log('All promises resolved, should not come here');
}, function error() {
console.log('One or more promises rejected, should come here');
});
_.delay(function() {
successPromise2.resolve();
}, 300);
_.delay(function() {
errorPromise2.reject();
}, 301);
*/