mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
fix(Shard): cleanup after settling spawn promise (#3799)
* clear sharding ready timeout * fix oops * update typings * commited to the wrong branch * fix(Shard): cleanup after settling the spawn promise Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
@@ -131,10 +131,37 @@ class Shard extends EventEmitter {
|
|||||||
|
|
||||||
if (spawnTimeout === -1 || spawnTimeout === Infinity) return this.process || this.worker;
|
if (spawnTimeout === -1 || spawnTimeout === Infinity) return this.process || this.worker;
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
this.once('ready', resolve);
|
const cleanup = () => {
|
||||||
this.once('disconnect', () => reject(new Error('SHARDING_READY_DISCONNECTED', this.id)));
|
clearTimeout(spawnTimeoutTimer);
|
||||||
this.once('death', () => reject(new Error('SHARDING_READY_DIED', this.id)));
|
this.off('ready', onReady);
|
||||||
setTimeout(() => reject(new Error('SHARDING_READY_TIMEOUT', this.id)), spawnTimeout);
|
this.off('disconnect', onDisconnect);
|
||||||
|
this.off('death', onDeath);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onReady = () => {
|
||||||
|
cleanup();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDisconnect = () => {
|
||||||
|
cleanup();
|
||||||
|
reject(new Error('SHARDING_READY_DISCONNECTED', this.id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDeath = () => {
|
||||||
|
cleanup();
|
||||||
|
reject(new Error('SHARDING_READY_DIED', this.id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const onTimeout = () => {
|
||||||
|
cleanup();
|
||||||
|
reject(new Error('SHARDING_READY_TIMEOUT', this.id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const spawnTimeoutTimer = setTimeout(onTimeout, spawnTimeout);
|
||||||
|
this.once('ready', onReady);
|
||||||
|
this.once('disconnect', onDisconnect);
|
||||||
|
this.once('death', onDeath);
|
||||||
});
|
});
|
||||||
return this.process || this.worker;
|
return this.process || this.worker;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user