Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly deprecated Timer class #4979

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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