Skip to content

Commit

Permalink
Properly deprecated Timer class (#4979)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky committed Jan 13, 2023
1 parent 57d3445 commit 02d0bfd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
43 changes: 1 addition & 42 deletions src/core/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,4 @@ const now = (typeof window !== 'undefined') && window.performance && window.perf
performance.now.bind(performance) :
Date.now;

/**
* A Timer counts milliseconds from when start() is called until when stop() is called.
*
* @ignore
*/
class Timer {
/**
* Create a new Timer instance.
*/
constructor() {
this._isRunning = false;
this._a = 0;
this._b = 0;
}

/**
* Start the timer.
*/
start() {
this._isRunning = true;
this._a = now();
}

/**
* Stop the timer.
*/
stop() {
this._isRunning = false;
this._b = now();
}

/**
* Get the number of milliseconds that passed between start() and stop() being called.
*
* @returns {number} The elapsed milliseconds.
*/
getMilliseconds() {
return this._b - this._a;
}
}

export { now, Timer };
export { now };
24 changes: 23 additions & 1 deletion src/deprecated/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { revision, version } from '../core/core.js';
import { string } from '../core/string.js';
import { Timer, now } from '../core/time.js';
import { now } from '../core/time.js';
import { Debug } from '../core/debug.js';

import { math } from '../core/math/math.js';
Expand Down Expand Up @@ -171,6 +171,28 @@ string.startsWith = function (s, subs) {
return s.startsWith(subs);
};

class Timer {
constructor() {
this._isRunning = false;
this._a = 0;
this._b = 0;
}

start() {
this._isRunning = true;
this._a = now();
}

stop() {
this._isRunning = false;
this._b = now();
}

getMilliseconds() {
return this._b - this._a;
}
}

export const time = {
now: now,
Timer: Timer
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export { WasmModule } from './core/wasm-module.js';
export { ReadStream } from './core/read-stream.js';
export { SortedLoopArray } from './core/sorted-loop-array.js';
export { Tags } from './core/tags.js';
export { Timer, now } from './core/time.js';
export { now } from './core/time.js';
export { URI, createURI } from './core/uri.js';
export { Tracing } from './core/tracing.js';

Expand Down

0 comments on commit 02d0bfd

Please sign in to comment.