Level 16

Promise.all keeps order

Two timers wrapped in promises, the slow one first. What does Promise.all hand back?

const wait = (ms, v) => new Promise((r) => setTimeout(() => r(v), ms));Promise.all([wait(30, 'slow'), wait(10, 'fast')])  .then((vals) => console.log(vals.join(',')));console.log('waiting');

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…