BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / kew / test / later.js

later.js

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
later.js 942 B Download Raw
1var Q = require('../kew')
2
3function synchronous (callback) {
4 callback()
5}
6
7var asynchronous = Q.getNextTickFunction()
8
9exports.testAsynchronousSynchronous = function (test) {
10 Q.setNextTickFunction(synchronous)
11
12 var number = 5
13
14 Q.resolve(true).then(function () {
15 number = 6
16 })
17 test.equals(number, 6, 'Q should resolve synchronously')
18
19 Q.setNextTickFunction(asynchronous)
20
21 Q.resolve(true).then(function () {
22 number = 7
23 })
24 test.equals(number, 6, 'Q should resolve asynchronously')
25 test.done()
26}
27
28exports.testSetImmediate = function (test) {
29 if (typeof setImmediate == 'undefined') {
30 test.done()
31 return
32 }
33
34 Q.setNextTickFunction(setImmediate)
35
36 var number = 5
37 Q.resolve(true).then(function () {
38 number = 6
39 })
40 test.equals(number, 5, 'Q should resolve asynchronously')
41 setImmediate(function () {
42 test.equals(number, 6, 'Q should schedule _successFn synchronously')
43 test.done()
44 })
45}