Skip to content

Commit

Permalink
feat(protocol/minecraft): reduce repeated code on promise.push
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminPerRam committed May 11, 2024
1 parent f52f9b2 commit 9bd3caa
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions protocols/minecraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,23 @@ export default class minecraft extends Core {
const vanillaResolver = new minecraftvanilla()
vanillaResolver.options = this.options
vanillaResolver.udpSocket = this.udpSocket
promises.push((async () => {
try { return await vanillaResolver.runOnceSafe() } catch (e) {}
})())
promises.push(vanillaResolver)

const gamespyResolver = new Gamespy3()
gamespyResolver.options = {
...this.options,
encoding: 'utf8'
}
gamespyResolver.udpSocket = this.udpSocket
promises.push((async () => {
try { return await gamespyResolver.runOnceSafe() } catch (e) {}
})())
promises.push(gamespyResolver)

const bedrockResolver = new minecraftbedrock()
bedrockResolver.options = this.options
bedrockResolver.udpSocket = this.udpSocket
promises.push((async () => {
try { return await bedrockResolver.runOnceSafe() } catch (e) {}
})())
promises.push(bedrockResolver)

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.gamespy = gamespyState
Expand Down

0 comments on commit 9bd3caa

Please sign in to comment.