summaryrefslogtreecommitdiff
path: root/cli/tests/testdata/workers/racy_worker.js
blob: 0f66c6278521fdb3877aba94a850a372cf244405 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// See issue for details
// https://github.com/denoland/deno/issues/4080
//
// After first received message, this worker schedules
// [assert(), close(), assert()] ops on the same turn of microtask queue
// All tasks after close should not make it

onmessage = async function () {
  let stage = 0;
  await new Promise((_) => {
    setTimeout(() => {
      if (stage !== 0) throw "Unexpected stage";
      stage = 1;
    }, 50);
    setTimeout(() => {
      if (stage !== 1) throw "Unexpected stage";
      stage = 2;
      postMessage("DONE");
      close();
    }, 50);
    setTimeout(() => {
      throw "This should not be run";
    }, 50);
  });
};