Created
October 22, 2016 12:23
-
-
Save talkol/5d0b02c4bde7d161d2f5d0319c695cad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
import fetch from 'node-fetch'; | |
import delay from 'delay'; | |
export async function pingServers(servers) { | |
let failedServers = {}; | |
for (const url of servers) { | |
let failures = 0; | |
for (const i of _.range(3)) { | |
const response = await fetch(url); | |
if (!response.ok) failures++; | |
await delay(10000); | |
} | |
if (failures > 0) failedServers[url] = failures; | |
} | |
return failedServers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I definitely love the
async
/await
features coming to Node.But, still, on "back-end" environments, GO might subjectively be better and might objectively outperform Node in multi-processor environments. The difference in performance between Node and GO might be negligible in single-processor environments.
For comparison purposes, here is my simple implementation of your
pinger-async-await.js
in GO: https://gist.github.com/pmbenjamin/c9dad251f6c8cd83bb6e5e9dbc8e883c