TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #3233 2.43K
CHALLENGE

const delay = (ms, val) => new Promise(res => setTimeout(res, ms, val));

async function* asyncGen() {
yield await delay(10, "alpha");
yield await delay(10, "beta");
yield await delay(10, "gamma");
}

async function run() {
const results = [];

const gen = asyncGen();
const [first, , third] = await Promise.all([
gen.next(),
gen.next(),
gen.next()
]);

results.push(first.value, third.value);

const p1 = Promise.resolve("x").then(v => v + "1");
const p2 = Promise.reject("err").catch(e => e + "2");

results.push(...(await Promise.all([p1, p2])));
console.log(results);
}

run();
  • ❤ 8
  • 👍 3
More from @javascript
  1. Sep 21, 2026Post #3509
  2. Sep 21, 2026CHALLENGE console.log( typeof typeof 1, 1 + typeof 1, 2 ** 3 ** 2, 1 + 2 + '3', 1 < 2 < 3,…
  3. Sep 20, 2026Post #3507
  4. Sep 20, 2026CHALLENGE 'use strict'; function getValue() { return this.value; } const obj = { value: 42…
  5. Sep 19, 2026Post #3505
  6. Sep 19, 2026CHALLENGE const a = 5 & 3; const b = 5 | 2; const c = ~5; const d = 1 << 31; const e = -1…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →