Skip to content

fix: Replace Date.now() with performance.now() #298

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

Open
wants to merge 1 commit into
base: 1.0.x-alpha
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/rsocket-core/src/RSocketSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class LeaseHandler implements LeaseManager {
) {}

handle(frame: LeaseFrame): void {
this.expirationTime = frame.ttl + Date.now();
this.expirationTime = frame.ttl + performance.now();
this.availableLease = frame.requestCount;

while (this.availableLease > 0 && this.pendingRequests.length > 0) {
Expand All @@ -213,7 +213,7 @@ export class LeaseHandler implements LeaseManager {

requestLease(handler: StreamFrameHandler & StreamLifecycleHandler): void {
const availableLease = this.availableLease;
if (availableLease > 0 && Date.now() < this.expirationTime) {
if (availableLease > 0 && performance.now() < this.expirationTime) {
this.availableLease = availableLease - 1;
this.multiplexer.createRequestStream(handler);
return;
Expand Down Expand Up @@ -414,7 +414,7 @@ export class KeepAliveHandler implements FrameHandler {
}

handle(frame: KeepAliveFrame): void {
this.keepAliveLastReceivedMillis = Date.now();
this.keepAliveLastReceivedMillis = performance.now();
if (Flags.hasRespond(frame.flags)) {
this.outbound.send({
type: FrameTypes.KEEPALIVE,
Expand All @@ -431,7 +431,7 @@ export class KeepAliveHandler implements FrameHandler {
return;
}

this.keepAliveLastReceivedMillis = Date.now();
this.keepAliveLastReceivedMillis = performance.now();
this.state = KeepAliveHandlerStates.Running;
this.activeTimeout = setTimeout(
this.timeoutCheck.bind(this),
Expand All @@ -454,7 +454,7 @@ export class KeepAliveHandler implements FrameHandler {
}

private timeoutCheck() {
const now = Date.now();
const now = performance.now();
const noKeepAliveDuration = now - this.keepAliveLastReceivedMillis;
if (noKeepAliveDuration >= this.keepAliveTimeoutDuration) {
this.connection.close(
Expand Down