mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
feat(protocol/minecraft): reduce repeated code on promise.push
This commit is contained in:
parent
f52f9b2322
commit
9bd3caab7b
1 changed files with 5 additions and 10 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue