Skip to content

Commit 9a6dccb

Browse files
Remove setNow from realtime-callbacks.ts (#2509)
Signed-off-by: Šimon Brandner <[email protected]>
1 parent 3935152 commit 9a6dccb

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

spec/unit/realtime-callbacks.spec.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import * as callbacks from "../../src/realtime-callbacks";
22

33
let wallTime = 1234567890;
4-
jest.useFakeTimers();
4+
jest.useFakeTimers().setSystemTime(wallTime);
55

66
describe("realtime-callbacks", function() {
77
function tick(millis) {
88
wallTime += millis;
99
jest.advanceTimersByTime(millis);
1010
}
1111

12-
beforeEach(function() {
13-
callbacks.setNow(() => wallTime);
14-
});
15-
16-
afterEach(function() {
17-
callbacks.setNow();
18-
});
19-
2012
describe("setTimeout", function() {
2113
it("should call the callback after the timeout", function() {
2214
const callback = jest.fn();

src/realtime-callbacks.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ const callbackList: {
4848
// var debuglog = logger.log.bind(logger);
4949
const debuglog = function(...params: any[]) {};
5050

51-
/**
52-
* Replace the function used by this module to get the current time.
53-
*
54-
* Intended for use by the unit tests.
55-
*
56-
* @param {function} [f] function which should return a millisecond counter
57-
*
58-
* @internal
59-
*/
60-
export function setNow(f: () => number): void {
61-
now = f || Date.now;
62-
}
63-
let now = Date.now;
64-
6551
/**
6652
* reimplementation of window.setTimeout, which will call the callback if
6753
* the wallclock time goes past the deadline.
@@ -78,7 +64,7 @@ export function setTimeout(func: (...params: any[]) => void, delayMs: number, ..
7864
delayMs = 0;
7965
}
8066

81-
const runAt = now() + delayMs;
67+
const runAt = Date.now() + delayMs;
8268
const key = count++;
8369
debuglog("setTimeout: scheduling cb", key, "at", runAt,
8470
"(delay", delayMs, ")");
@@ -141,7 +127,7 @@ function scheduleRealCallback(): void {
141127
return;
142128
}
143129

144-
const timestamp = now();
130+
const timestamp = Date.now();
145131
const delayMs = Math.min(first.runAt - timestamp, TIMER_CHECK_PERIOD_MS);
146132

147133
debuglog("scheduleRealCallback: now:", timestamp, "delay:", delayMs);
@@ -150,7 +136,7 @@ function scheduleRealCallback(): void {
150136

151137
function runCallbacks(): void {
152138
let cb;
153-
const timestamp = now();
139+
const timestamp = Date.now();
154140
debuglog("runCallbacks: now:", timestamp);
155141

156142
// get the list of things to call

0 commit comments

Comments
 (0)