-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (37 loc) · 1.01 KB
/
index.js
File metadata and controls
50 lines (37 loc) · 1.01 KB
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
46
47
48
49
function getTicker(log) {
log = log || Function.prototype
var nativeNextTick = process.nextTick
var ticking = false
function nextTick() {
if (!ticking) {
++nextTick._tick
ticking = true
nativeNextTick(function () {
log(nextTick._tick)
// Do not put this statement before the one above
// That would cause `nextTick` calling itself forever
ticking = false
})
}
nativeNextTick.apply(null, arguments)
}
nextTick._tick = 0
return nextTick
}
// Only for test
exports._nextTick = getTicker()
exports.polyfill = function (opts) {
// already hacked
if (process.nextTick._tick != null) return
var env = process.env.NODE_DEBUG
if (!env || !/\bnexttick\b/.test(env)) return
opts = opts || {}
var template = '---------- TICK %d ----------'
if (opts.color) {
template = '\x1b[32m' + template + '\x1b[0m'
}
var log = opts.log !== false && function (tick) {
console.error(template, tick)
}
process.nextTick = getTicker(log)
}