2009-10-05 15:46:31 +02:00
|
|
|
node.mixin(require("common.js"));
|
2009-08-26 17:12:44 +02:00
|
|
|
|
|
|
|
var p1_done = false;
|
|
|
|
var p1 = new node.Promise();
|
|
|
|
p1.addCallback(function () {
|
|
|
|
assertEquals(1, arguments.length);
|
|
|
|
assertEquals("single arg", arguments[0]);
|
|
|
|
p1_done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var p2_done = false;
|
|
|
|
var p2 = new node.Promise();
|
|
|
|
p2.addCallback(function () {
|
|
|
|
p2_done = true;
|
|
|
|
setTimeout(function () {
|
2009-09-12 13:01:03 +02:00
|
|
|
p1.emitSuccess("single arg");
|
2009-08-26 17:12:44 +02:00
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
var p3_done = false;
|
|
|
|
var p3 = new node.Promise();
|
|
|
|
p3.addCallback(function () {
|
|
|
|
p3_done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var p4_done = false;
|
|
|
|
var p4 = new node.Promise();
|
|
|
|
p4.addCallback(function () {
|
|
|
|
assertEquals(3, arguments.length);
|
|
|
|
assertEquals("a", arguments[0]);
|
|
|
|
assertEquals("b", arguments[1]);
|
|
|
|
assertEquals("c", arguments[2]);
|
|
|
|
p4_done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var p5_done = false;
|
|
|
|
var p5 = new node.Promise();
|
|
|
|
p5.addCallback(function () {
|
|
|
|
p5_done = true;
|
|
|
|
setTimeout(function () {
|
2009-09-12 13:01:03 +02:00
|
|
|
p4.emitSuccess("a","b","c");
|
2009-08-26 17:12:44 +02:00
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
p2.emitSuccess();
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertFalse(p1_done);
|
|
|
|
assertTrue(p2_done);
|
|
|
|
assertFalse(p3_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var ret1 = p1.wait()
|
|
|
|
assertEquals("single arg", ret1);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertTrue(p1_done);
|
|
|
|
assertTrue(p2_done);
|
|
|
|
assertFalse(p3_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
p3.emitSuccess();
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertFalse(p4_done);
|
|
|
|
assertFalse(p5_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
p5.emitSuccess();
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertFalse(p4_done);
|
|
|
|
assertTrue(p5_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var ret4 = p4.wait();
|
|
|
|
assertArrayEquals(["a","b","c"], ret4);
|
|
|
|
|
|
|
|
assertTrue(p4_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-08-26 17:12:44 +02:00
|
|
|
assertTrue(p1_done);
|
|
|
|
assertTrue(p2_done);
|
|
|
|
assertTrue(p3_done);
|
|
|
|
assertTrue(p4_done);
|
|
|
|
assertTrue(p5_done);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|