mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
refactor(Util): replace Util.delayFor with tp.setTimeout (#7082)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
const EventEmitter = require('node:events');
|
||||
const path = require('node:path');
|
||||
const { setTimeout: sleep } = require('node:timers/promises');
|
||||
const { Error } = require('../errors');
|
||||
const Util = require('../util/Util');
|
||||
let childProcess = null;
|
||||
@@ -201,7 +202,7 @@ class Shard extends EventEmitter {
|
||||
*/
|
||||
async respawn({ delay = 500, timeout = 30_000 } = {}) {
|
||||
this.kill();
|
||||
if (delay > 0) await Util.delayFor(delay);
|
||||
if (delay > 0) await sleep(delay);
|
||||
return this.spawn(timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const EventEmitter = require('node:events');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { setTimeout: sleep } = require('node:timers/promises');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Shard = require('./Shard');
|
||||
const { Error, TypeError, RangeError } = require('../errors');
|
||||
@@ -214,7 +215,7 @@ class ShardingManager extends EventEmitter {
|
||||
const promises = [];
|
||||
const shard = this.createShard(shardId);
|
||||
promises.push(shard.spawn(timeout));
|
||||
if (delay > 0 && this.shards.size !== this.shardList.length) promises.push(Util.delayFor(delay));
|
||||
if (delay > 0 && this.shards.size !== this.shardList.length) promises.push(sleep(delay));
|
||||
await Promise.all(promises); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
|
||||
@@ -306,7 +307,7 @@ class ShardingManager extends EventEmitter {
|
||||
let s = 0;
|
||||
for (const shard of this.shards.values()) {
|
||||
const promises = [shard.respawn({ respawnDelay, timeout })];
|
||||
if (++s < this.shards.size && shardDelay > 0) promises.push(Util.delayFor(shardDelay));
|
||||
if (++s < this.shards.size && shardDelay > 0) promises.push(sleep(shardDelay));
|
||||
await Promise.all(promises); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
return this.shards;
|
||||
|
||||
Reference in New Issue
Block a user