From c49d463858355c93e556b5ca2b54e91a79ac021d Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Sun, 5 Nov 2023 23:50:43 +0200 Subject: [PATCH] feat: Use async/await on attempt_protocols --- tools/attempt_protocols.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/attempt_protocols.js b/tools/attempt_protocols.js index bf58559..1d44dbf 100644 --- a/tools/attempt_protocols.js +++ b/tools/attempt_protocols.js @@ -17,17 +17,20 @@ const gamedig = new GameDig(options) const protocols = ['valve', 'gamespy1', 'gamespy2', 'gamespy3', 'goldsrc', 'minecraft', 'quake1', 'quake2', 'quake3', 'unreal2', 'valve'] -protocols.forEach(protocol => { - gamedig.query({ - ...options, - debug: true, - type: `protocol-${protocol}` - }) - .then(data => { - console.log(data) +const run = async () => { + for (const protocol of protocols) { + try { + const response = await gamedig.query({ + ...options, + debug: true, + type: `protocol-${protocol}` + }) + console.log(response) process.exit() - }) - .catch(error => { - console.log(`Error on '${protocol}': ${error}`) - }) -}) + } catch (e) { + console.log(`Error on '${protocol}': ${e}`) + } + } +} + +run().then(() => {})