mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c506660f32
For lint exceptions that are universal or near universal for `test/common`, put the exceptions in a config file rather than disabling the ESLint rules at the top of each file. PR-URL: https://github.com/nodejs/node/pull/39358 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
29 lines
590 B
JavaScript
29 lines
590 B
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const kLimit = Symbol('limit');
|
|
const kCallback = Symbol('callback');
|
|
const common = require('./');
|
|
|
|
class Countdown {
|
|
constructor(limit, cb) {
|
|
assert.strictEqual(typeof limit, 'number');
|
|
assert.strictEqual(typeof cb, 'function');
|
|
this[kLimit] = limit;
|
|
this[kCallback] = common.mustCall(cb);
|
|
}
|
|
|
|
dec() {
|
|
assert(this[kLimit] > 0, 'Countdown expired');
|
|
if (--this[kLimit] === 0)
|
|
this[kCallback]();
|
|
return this[kLimit];
|
|
}
|
|
|
|
get remaining() {
|
|
return this[kLimit];
|
|
}
|
|
}
|
|
|
|
module.exports = Countdown;
|