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.
Run code runs your code once for each case. It compares what your code prints with the expected output.
Starter code
or press Ctrl EnterNot run yet
cases
Not run yetTwo steps and two cancellations
Expected output
1
open form started2
open form done3
fill form started4
fill form done5
cancel 7 started6
cancel 9 started7
cancel 7 done8
cancel 9 done9
finishedSee 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
1
open form started2
open form done3
fill form started4
fill form done5
send form started6
send form done7
finishedSee 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 = [];