2009-10-31 19:02:30 +01:00
|
|
|
process.mixin(require("./common"));
|
2010-01-15 21:46:08 +01:00
|
|
|
events = require('events');
|
2009-08-26 17:12:44 +02:00
|
|
|
|
|
|
|
var p1_done = false;
|
2010-01-15 21:46:08 +01:00
|
|
|
var p1 = new events.Promise();
|
2009-08-26 17:12:44 +02:00
|
|
|
p1.addCallback(function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(1, arguments.length);
|
|
|
|
assert.equal("single arg", arguments[0]);
|
2009-08-26 17:12:44 +02:00
|
|
|
p1_done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var p2_done = false;
|
2010-01-15 21:46:08 +01:00
|
|
|
var p2 = new events.Promise();
|
2009-08-26 17:12:44 +02:00
|
|
|
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;
|
2010-01-15 21:46:08 +01:00
|
|
|
var p3 = new events.Promise();
|
2009-08-26 17:12:44 +02:00
|
|
|
p3.addCallback(function () {
|
|
|
|
p3_done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var p4_done = false;
|
2010-01-15 21:46:08 +01:00
|
|
|
var p4 = new events.Promise();
|
2009-08-26 17:12:44 +02:00
|
|
|
p4.addCallback(function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(3, arguments.length);
|
|
|
|
assert.equal("a", arguments[0]);
|
|
|
|
assert.equal("b", arguments[1]);
|
|
|
|
assert.equal("c", arguments[2]);
|
2009-08-26 17:12:44 +02:00
|
|
|
p4_done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var p5_done = false;
|
2010-01-15 21:46:08 +01:00
|
|
|
var p5 = new events.Promise();
|
2009-08-26 17:12:44 +02:00
|
|
|
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-11-28 18:26:59 +01:00
|
|
|
assert.equal(false, p1_done);
|
|
|
|
assert.equal(true, p2_done);
|
|
|
|
assert.equal(false, p3_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var ret1 = p1.wait()
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal("single arg", ret1);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(true, p1_done);
|
|
|
|
assert.equal(true, p2_done);
|
|
|
|
assert.equal(false, 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-11-28 18:26:59 +01:00
|
|
|
assert.equal(false, p4_done);
|
|
|
|
assert.equal(false, 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-11-28 18:26:59 +01:00
|
|
|
assert.equal(false, p4_done);
|
|
|
|
assert.equal(true, p5_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var ret4 = p4.wait();
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.deepEqual(["a","b","c"], ret4);
|
2009-08-26 18:22:00 +02:00
|
|
|
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(true, p4_done);
|
2009-08-26 17:12:44 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(true, p1_done);
|
|
|
|
assert.equal(true, p2_done);
|
|
|
|
assert.equal(true, p3_done);
|
|
|
|
assert.equal(true, p4_done);
|
|
|
|
assert.equal(true, p5_done);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|