mirror of https://github.com/lukechilds/node.git
Felix Geisendörfer
15 years ago
committed by
Ryan Dahl
3 changed files with 101 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||
node.mixin(require("common.js")); |
|||
|
|||
var cancelFired = false; |
|||
|
|||
var promise = new node.Promise(); |
|||
promise.addCallback(function() { |
|||
assertUnreachable('addCallback should not fire after promise.cancel()'); |
|||
}); |
|||
|
|||
promise.addErrback(function() { |
|||
assertUnreachable('addErrback should not fire after promise.cancel()'); |
|||
}); |
|||
|
|||
promise.addCancelback(function() { |
|||
cancelFired = true; |
|||
}); |
|||
|
|||
promise.cancel(); |
|||
|
|||
setTimeout(function() { |
|||
promise.emitSuccess(); |
|||
promise.emitError(); |
|||
}, 100); |
|||
|
|||
process.addListener('exit', function() { |
|||
assertTrue(cancelFired); |
|||
}); |
@ -0,0 +1,34 @@ |
|||
node.mixin(require("common.js")); |
|||
|
|||
var timeouts = 0; |
|||
|
|||
var promise = new node.Promise(); |
|||
promise.timeout(250); |
|||
assertEquals(250, promise.timeout()); |
|||
|
|||
promise.addCallback(function() { |
|||
assertUnreachable('addCallback should not fire after a promise error'); |
|||
}); |
|||
|
|||
promise.addErrback(function(e) { |
|||
assertInstanceof(e, Error); |
|||
assertEquals('timeout', e.message); |
|||
timeouts++; |
|||
}); |
|||
|
|||
setTimeout(function() { |
|||
promise.emitSuccess('Am I too late?'); |
|||
}, 500); |
|||
|
|||
var waitPromise = new node.Promise(); |
|||
try { |
|||
waitPromise.timeout(250).wait() |
|||
} catch (e) { |
|||
assertInstanceof(e, Error); |
|||
assertEquals('timeout', e.message); |
|||
timeouts++; |
|||
} |
|||
|
|||
process.addListener('exit', function() { |
|||
assertEquals(2, timeouts); |
|||
}); |
Loading…
Reference in new issue