later.js
942 Bytes
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
44
45
var Q = require('../kew')
function synchronous (callback) {
callback()
}
var asynchronous = Q.getNextTickFunction()
exports.testAsynchronousSynchronous = function (test) {
Q.setNextTickFunction(synchronous)
var number = 5
Q.resolve(true).then(function () {
number = 6
})
test.equals(number, 6, 'Q should resolve synchronously')
Q.setNextTickFunction(asynchronous)
Q.resolve(true).then(function () {
number = 7
})
test.equals(number, 6, 'Q should resolve asynchronously')
test.done()
}
exports.testSetImmediate = function (test) {
if (typeof setImmediate == 'undefined') {
test.done()
return
}
Q.setNextTickFunction(setImmediate)
var number = 5
Q.resolve(true).then(function () {
number = 6
})
test.equals(number, 5, 'Q should resolve asynchronously')
setImmediate(function () {
test.equals(number, 6, 'Q should schedule _successFn synchronously')
test.done()
})
}