Skip to content

Instantly share code, notes, and snippets.

@talkol
Created October 22, 2016 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save talkol/5d0b02c4bde7d161d2f5d0319c695cad to your computer and use it in GitHub Desktop.
Save talkol/5d0b02c4bde7d161d2f5d0319c695cad to your computer and use it in GitHub Desktop.
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;
}
@pbnj
Copy link

pbnj commented Oct 25, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment