Created
August 28, 2018 23:14
-
-
Save ThomasG77/ea8c1ed00369f9facd38a643720a49e4 to your computer and use it in GitHub Desktop.
Promise.race illustrated with sourceforge mirrors
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
const fetch = require('node-fetch'); | |
const mirrors = ['astuteinternet', 'ayera', 'cfhcable', 'cytranet', 'datapacket', 'excellmedia', 'freefr', 'gigenet', 'iweb', 'jaist', 'kent', 'liquidtelecom', 'managedway', 'nchc', 'netcologne', 'netix', 'newcontinuum', 'phoenixnap', 'pilotfiber', 'razaoinfo', 'superb-dca2', 'superb-sea2', 'svwh', 'tenet', 'ufpr', 'versaweb']; | |
const url = 'https://sourceforge.net/projects/filezilla/files/FileZilla_Client/3.31.0/FileZilla_3.31.0_win64-setup.exe/download'; | |
// Find the fastest Sourceforge mirror manually | |
// The usual use case would for Promise.race would be | |
// when calling images from multiple servers | |
// (imagine different AWS S3 storage) to get the fastest one | |
var p = Promise.race( | |
mirrors.map((mirror, index) => { | |
return fetch(`${url}?use_mirror=${mirror}`); | |
}) | |
); | |
p.then(response => console.log(response.url)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment