refactor(Util): replace Util.delayFor with tp.setTimeout (#7082)

This commit is contained in:
Antonio Román
2021-12-08 21:31:01 +01:00
committed by GitHub
parent 23513d1917
commit 25b8491235
6 changed files with 11 additions and 22 deletions

View File

@@ -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;