feat(protocol/minecraft): reduce repeated code on promise.push

This commit is contained in:
CosminPerRam 2024-05-11 18:47:38 +03:00
parent f52f9b2322
commit 9bd3caab7b

View file

@ -24,9 +24,7 @@ export default class minecraft extends Core {
const vanillaResolver = new minecraftvanilla() const vanillaResolver = new minecraftvanilla()
vanillaResolver.options = this.options vanillaResolver.options = this.options
vanillaResolver.udpSocket = this.udpSocket vanillaResolver.udpSocket = this.udpSocket
promises.push((async () => { promises.push(vanillaResolver)
try { return await vanillaResolver.runOnceSafe() } catch (e) {}
})())
const gamespyResolver = new Gamespy3() const gamespyResolver = new Gamespy3()
gamespyResolver.options = { gamespyResolver.options = {
@ -34,18 +32,15 @@ export default class minecraft extends Core {
encoding: 'utf8' encoding: 'utf8'
} }
gamespyResolver.udpSocket = this.udpSocket gamespyResolver.udpSocket = this.udpSocket
promises.push((async () => { promises.push(gamespyResolver)
try { return await gamespyResolver.runOnceSafe() } catch (e) {}
})())
const bedrockResolver = new minecraftbedrock() const bedrockResolver = new minecraftbedrock()
bedrockResolver.options = this.options bedrockResolver.options = this.options
bedrockResolver.udpSocket = this.udpSocket bedrockResolver.udpSocket = this.udpSocket
promises.push((async () => { promises.push(bedrockResolver)
try { return await bedrockResolver.runOnceSafe() } catch (e) {}
})())
const [vanillaState, gamespyState, bedrockState] = await Promise.all(promises) const ranPromises = promises.map(p => p.runOnceSafe().catch(_ => undefined))
const [vanillaState, gamespyState, bedrockState] = await Promise.all(ranPromises)
state.raw.vanilla = vanillaState state.raw.vanilla = vanillaState
state.raw.gamespy = gamespyState state.raw.gamespy = gamespyState