The loop that does not wait

Dependent steps must finish in order. Independent cancellations can start together.

your task

Finish each form step before starting the next. Then start all cancellations before any cancellation finishes. Print “finished” last, including when there are no cancellations.

The script starts the form steps and cancellations, then prints “finished” while work is still running. Each call to work reports when it starts and when it finishes.

Starter code
or press Ctrl EnterNot run yet

cases

Not run yetTwo steps and two cancellations

Expected output

1open form started
2open form done
3fill form started
4fill form done
5cancel 7 started
6cancel 9 started
7cancel 7 done
8cancel 9 done
9finished
See the input and the code for this case
function work(label) {
  console.log(label + " started");
  return Promise.resolve().then(() => {
    console.log(label + " done");
  });
}
const steps = ["open form", "fill form"];
const ids = [7, 9];
Not run yetThree steps and no cancellations

Expected output

1open form started
2open form done
3fill form started
4fill form done
5send form started
6send form done
7finished
See the input and the code for this case
function work(label) {
  console.log(label + " started");
  return Promise.resolve().then(() => {
    console.log(label + " done");
  });
}
const steps = ["open form", "fill form", "send form"];
const ids = [];