Created
January 21, 2016 21:59
-
-
Save hontas/4b8642c05059e2e89ce6 to your computer and use it in GitHub Desktop.
Some snippets of ES7
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
function makeRequest(id) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (id % 2) { | |
resolve(id); | |
} else { | |
reject(id); | |
} | |
}, 400); | |
}); | |
} | |
async function resourceCrawler() { | |
const result = []; | |
for (let id = 1; id < 10; id++) { | |
try { | |
const response = await makeRequest(id); | |
result.push(response); | |
} catch (err) { | |
console.log(`No resource on id: ${id}`); | |
} | |
} | |
return result; | |
} | |
resourceCrawler() | |
.then((res) => console.log(`Resources @ ${res}`)); | |
//------------------------- | |
function* range(from, to, step = 1) { | |
for (let i = from; i <= to; i += step) { | |
yield i; | |
} | |
} | |
console.log([...range(1, 5)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment