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
// async_scrape.js (tested with node 11.3) | |
const sleep = ts => new Promise(resolve => setTimeout(resolve, ts * 1000)); | |
async function fetchUrl(url) { | |
console.log(`~ executing fetchUrl(${url})`); | |
console.time(`fetchUrl(${url})`); | |
await sleep(1 + Math.random() * 4); | |
console.timeEnd(`fetchUrl(${url})`); | |
return `<em>fake</em> page html for ${url}`; | |
} | |
async function analyzeSentiment(html) { | |
console.log(`~ analyzeSentiment("${html}")`); | |
console.time(`analyzeSentiment("${html}")`); | |
await sleep(1 + Math.random() * 4); | |
const r = { | |
positive: Math.random() | |
} | |
console.timeEnd(`analyzeSentiment("${html}")`); | |
return r; | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment