Socket
Socket
Sign inDemoInstall

@grpc/grpc-js

Package Overview
Dependencies
Maintainers
3
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grpc/grpc-js - npm Package Compare versions

Comparing version 1.6.1 to 1.6.2

56

build/src/backoff-timeout.d.ts

@@ -9,11 +9,45 @@ export interface BackoffOptions {

private callback;
private initialDelay;
private multiplier;
private maxDelay;
private jitter;
/**
* The delay time at the start, and after each reset.
*/
private readonly initialDelay;
/**
* The exponential backoff multiplier.
*/
private readonly multiplier;
/**
* The maximum delay time
*/
private readonly maxDelay;
/**
* The maximum fraction by which the delay time can randomly vary after
* applying the multiplier.
*/
private readonly jitter;
/**
* The delay time for the next time the timer runs.
*/
private nextDelay;
/**
* The handle of the underlying timer. If running is false, this value refers
* to an object representing a timer that has ended, but it can still be
* interacted with without error.
*/
private timerId;
/**
* Indicates whether the timer is currently running.
*/
private running;
/**
* Indicates whether the timer should keep the Node process running if no
* other async operation is doing so.
*/
private hasRef;
/**
* The time that the currently running timer was started. Only valid if
* running is true.
*/
private startTime;
constructor(callback: () => void, options?: BackoffOptions);
private runTimer;
/**

@@ -29,8 +63,20 @@ * Call the callback after the current amount of delay time

/**
* Reset the delay time to its initial value.
* Reset the delay time to its initial value. If the timer is still running,
* retroactively apply that reset to the current timer.
*/
reset(): void;
/**
* Check whether the timer is currently running.
*/
isRunning(): boolean;
/**
* Set that while the timer is running, it should keep the Node process
* running.
*/
ref(): void;
/**
* Set that while the timer is running, it should not keep the Node process
* running.
*/
unref(): void;
}

@@ -35,8 +35,33 @@ "use strict";

this.callback = callback;
/**
* The delay time at the start, and after each reset.
*/
this.initialDelay = INITIAL_BACKOFF_MS;
/**
* The exponential backoff multiplier.
*/
this.multiplier = BACKOFF_MULTIPLIER;
/**
* The maximum delay time
*/
this.maxDelay = MAX_BACKOFF_MS;
/**
* The maximum fraction by which the delay time can randomly vary after
* applying the multiplier.
*/
this.jitter = BACKOFF_JITTER;
/**
* Indicates whether the timer is currently running.
*/
this.running = false;
/**
* Indicates whether the timer should keep the Node process running if no
* other async operation is doing so.
*/
this.hasRef = true;
/**
* The time that the currently running timer was started. Only valid if
* running is true.
*/
this.startTime = new Date();
if (options) {

@@ -60,15 +85,19 @@ if (options.initialDelay) {

}
/**
* Call the callback after the current amount of delay time
*/
runOnce() {
runTimer(delay) {
var _a, _b;
this.running = true;
this.timerId = setTimeout(() => {
this.callback();
this.running = false;
}, this.nextDelay);
}, delay);
if (!this.hasRef) {
(_b = (_a = this.timerId).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
}
}
/**
* Call the callback after the current amount of delay time
*/
runOnce() {
this.running = true;
this.startTime = new Date();
this.runTimer(this.nextDelay);
const nextBackoff = Math.min(this.nextDelay * this.multiplier, this.maxDelay);

@@ -88,10 +117,30 @@ const jitterMagnitude = nextBackoff * this.jitter;

/**
* Reset the delay time to its initial value.
* Reset the delay time to its initial value. If the timer is still running,
* retroactively apply that reset to the current timer.
*/
reset() {
this.nextDelay = this.initialDelay;
if (this.running) {
const now = new Date();
const newEndTime = this.startTime;
newEndTime.setMilliseconds(newEndTime.getMilliseconds() + this.nextDelay);
clearTimeout(this.timerId);
if (now < newEndTime) {
this.runTimer(newEndTime.getTime() - now.getTime());
}
else {
this.running = false;
}
}
}
/**
* Check whether the timer is currently running.
*/
isRunning() {
return this.running;
}
/**
* Set that while the timer is running, it should keep the Node process
* running.
*/
ref() {

@@ -102,2 +151,6 @@ var _a, _b;

}
/**
* Set that while the timer is running, it should not keep the Node process
* running.
*/
unref() {

@@ -104,0 +157,0 @@ var _a, _b;

2

package.json
{
"name": "@grpc/grpc-js",
"version": "1.6.1",
"version": "1.6.2",
"description": "gRPC Library for Node - pure JS implementation",

@@ -5,0 +5,0 @@ "homepage": "https://grpc.io/",

@@ -40,10 +40,43 @@ /*

export class BackoffTimeout {
private initialDelay: number = INITIAL_BACKOFF_MS;
private multiplier: number = BACKOFF_MULTIPLIER;
private maxDelay: number = MAX_BACKOFF_MS;
private jitter: number = BACKOFF_JITTER;
/**
* The delay time at the start, and after each reset.
*/
private readonly initialDelay: number = INITIAL_BACKOFF_MS;
/**
* The exponential backoff multiplier.
*/
private readonly multiplier: number = BACKOFF_MULTIPLIER;
/**
* The maximum delay time
*/
private readonly maxDelay: number = MAX_BACKOFF_MS;
/**
* The maximum fraction by which the delay time can randomly vary after
* applying the multiplier.
*/
private readonly jitter: number = BACKOFF_JITTER;
/**
* The delay time for the next time the timer runs.
*/
private nextDelay: number;
/**
* The handle of the underlying timer. If running is false, this value refers
* to an object representing a timer that has ended, but it can still be
* interacted with without error.
*/
private timerId: NodeJS.Timer;
/**
* Indicates whether the timer is currently running.
*/
private running = false;
/**
* Indicates whether the timer should keep the Node process running if no
* other async operation is doing so.
*/
private hasRef = true;
/**
* The time that the currently running timer was started. Only valid if
* running is true.
*/
private startTime: Date = new Date();

@@ -70,14 +103,19 @@ constructor(private callback: () => void, options?: BackoffOptions) {

/**
* Call the callback after the current amount of delay time
*/
runOnce() {
this.running = true;
private runTimer(delay: number) {
this.timerId = setTimeout(() => {
this.callback();
this.running = false;
}, this.nextDelay);
}, delay);
if (!this.hasRef) {
this.timerId.unref?.();
}
}
/**
* Call the callback after the current amount of delay time
*/
runOnce() {
this.running = true;
this.startTime = new Date();
this.runTimer(this.nextDelay);
const nextBackoff = Math.min(

@@ -102,8 +140,23 @@ this.nextDelay * this.multiplier,

/**
* Reset the delay time to its initial value.
* Reset the delay time to its initial value. If the timer is still running,
* retroactively apply that reset to the current timer.
*/
reset() {
this.nextDelay = this.initialDelay;
if (this.running) {
const now = new Date();
const newEndTime = this.startTime;
newEndTime.setMilliseconds(newEndTime.getMilliseconds() + this.nextDelay);
clearTimeout(this.timerId);
if (now < newEndTime) {
this.runTimer(newEndTime.getTime() - now.getTime());
} else {
this.running = false;
}
}
}
/**
* Check whether the timer is currently running.
*/
isRunning() {

@@ -113,2 +166,6 @@ return this.running;

/**
* Set that while the timer is running, it should keep the Node process
* running.
*/
ref() {

@@ -119,2 +176,6 @@ this.hasRef = true;

/**
* Set that while the timer is running, it should not keep the Node process
* running.
*/
unref() {

@@ -121,0 +182,0 @@ this.hasRef = false;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc