summaryrefslogtreecommitdiff
path: root/test/sequential/test-timers-set-interval-excludes-callback-duration.js
blob: 90eb16b0e259b3273ba4410f27e219a2ac4d3c11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
const common = require('../common');
const assert = require('assert');

let cntr = 0;
let first;
const t = setInterval(() => {
  cntr++;
  if (cntr === 1) {
    common.busyLoop(100);
    // Ensure that the event loop passes before the second interval
    setImmediate(() => assert.strictEqual(cntr, 1));
    first = Date.now();
  } else if (cntr === 2) {
    assert(Date.now() - first < 100);
    clearInterval(t);
  }
}, 100);
const t2 = setInterval(() => {
  if (cntr === 2) {
    clearInterval(t2);
  }
}, 100);