mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
45 lines
942 B
JavaScript
45 lines
942 B
JavaScript
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()
|
|
})
|
|
}
|