Command Palette

Search for a command to run...

Hectal
Phase 10: Asynchronous JavaScript
JavaScript · Exercise 3 of 5 PreviousNext
Intermediate

Promise helpers: delay and a promisified API

1. Write delay(ms, value): it returns a promise that fulfils with value after ms milliseconds.

2. readConfig(name, callback) is an old error-first callback API (don't change it). Write readConfigAsync(name) that returns a promise: fulfilled with the config, or rejected with the error the callback received.

What Check tests

  1. delay returns a promise
  2. delay(150, "hi") fulfils with hi after at least 150 ms
  3. readConfigAsync("app") fulfils with the config
  4. readConfigAsync("db") rejects with the original error

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.