mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
fix(Shard): use provided timeout when respawning (#6735)
This commit is contained in:
@@ -92,7 +92,7 @@ class Shard extends EventEmitter {
|
||||
* @type {Function}
|
||||
* @private
|
||||
*/
|
||||
this._exitListener = this._handleExit.bind(this, undefined);
|
||||
this._exitListener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +106,8 @@ class Shard extends EventEmitter {
|
||||
if (this.process) throw new Error('SHARDING_PROCESS_EXISTS', this.id);
|
||||
if (this.worker) throw new Error('SHARDING_WORKER_EXISTS', this.id);
|
||||
|
||||
this._exitListener = this._handleExit.bind(this, undefined, timeout);
|
||||
|
||||
if (this.manager.mode === 'process') {
|
||||
this.process = childProcess
|
||||
.fork(path.resolve(this.manager.file), this.args, {
|
||||
@@ -132,7 +134,7 @@ class Shard extends EventEmitter {
|
||||
*/
|
||||
this.emit('spawn', child);
|
||||
|
||||
if (timeout === -1 || timeout === Infinity) return child;
|
||||
if (timeout === -1 || timeout === Infinity) return Promise.resolve(child);
|
||||
return new Promise((resolve, reject) => {
|
||||
const cleanup = () => {
|
||||
clearTimeout(spawnTimeoutTimer);
|
||||
@@ -379,9 +381,11 @@ class Shard extends EventEmitter {
|
||||
/**
|
||||
* Handles the shard's process/worker exiting.
|
||||
* @param {boolean} [respawn=this.manager.respawn] Whether to spawn the shard again
|
||||
* @param {number} [timeout] The amount in milliseconds to wait until the {@link Client}
|
||||
* has become ready (`-1` or `Infinity` for no wait)
|
||||
* @private
|
||||
*/
|
||||
_handleExit(respawn = this.manager.respawn) {
|
||||
_handleExit(respawn = this.manager.respawn, timeout) {
|
||||
/**
|
||||
* Emitted upon the shard's child process/worker exiting.
|
||||
* @event Shard#death
|
||||
@@ -395,7 +399,7 @@ class Shard extends EventEmitter {
|
||||
this._evals.clear();
|
||||
this._fetches.clear();
|
||||
|
||||
if (respawn) this.spawn().catch(err => this.emit('error', err));
|
||||
if (respawn) this.spawn(timeout).catch(err => this.emit('error', err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -1677,7 +1677,7 @@ export class Shard extends EventEmitter {
|
||||
private _evals: Map<string, Promise<unknown>>;
|
||||
private _exitListener: (...args: any[]) => void;
|
||||
private _fetches: Map<string, Promise<unknown>>;
|
||||
private _handleExit(respawn?: boolean): void;
|
||||
private _handleExit(respawn?: boolean, timeout?: number): void;
|
||||
private _handleMessage(message: unknown): void;
|
||||
|
||||
public args: string[];
|
||||
|
||||
Reference in New Issue
Block a user