summaryrefslogtreecommitdiff
path: root/test/parallel/test-timers-immediate.js
blob: cd0a423f4d963a4d242b1b1e9b4ec9b839c5c707 (plain)
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
'use strict';
require('../common');
var assert = require('assert');

let immediateA = false;
let immediateB = false;
let immediateC = [];

setImmediate(function() {
  try {
    immediateA = process.hrtime(before);
  } catch (e) {
    console.log('failed to get hrtime with offset');
  }
  clearImmediate(immediateB);
});

const before = process.hrtime();

immediateB = setImmediate(function() {
  immediateB = true;
});

setImmediate(function(x, y, z) {
  immediateC = [x, y, z];
}, 1, 2, 3);

process.on('exit', function() {
  assert.ok(immediateA, 'Immediate should happen after normal execution');
  assert.notStrictEqual(immediateB, true, 'immediateB should not fire');
  assert.deepStrictEqual(immediateC, [1, 2, 3], 'immediateC args should match');
});