Not ES6, but with async/await, I tend to put this in the top of quite a few of my files, easier as a oneliner than pulling in from a library module a lot of the time.
const sleep = ms => new Promise(res => setTimeout(res, ms));
Actually the object spread operator is part of ESNext, so no need to bring JSX up. And it's *so* much better than Object.assign to create immutable objects.
Basically,
const foo = { ...bar };
is equivalent to
const foo = Object.assign({}, bar);
but the former is more compact and readable than the latter.
Not ES6, but with async/await, I tend to put this in the top of quite a few of my files, easier as a oneliner than pulling in from a library module a lot of the time. const sleep = ms => new Promise(res => setTimeout(res, ms));Another one relatively simple: const promisify = fn => (...args) => new Promise(resolve, reject) { fn(...args, (err, result) => { if (err) return reject(err) resolve(result) } }Actually the object spread operator is part of ESNext, so no need to bring JSX up. And it's *so* much better than Object.assign to create immutable objects. Basically, const foo = { ...bar }; is equivalent to const foo = Object.assign({}, bar); but the former is more compact and readable than the latter.