Skip to content

Instantly share code, notes, and snippets.

@hontas
Created January 21, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hontas/4b8642c05059e2e89ce6 to your computer and use it in GitHub Desktop.
Save hontas/4b8642c05059e2e89ce6 to your computer and use it in GitHub Desktop.
Some snippets of ES7
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