Skip to content

Instantly share code, notes, and snippets.

@hontas

hontas/ES7.js

Created Jan 21, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.