chromium/third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js

globalThis.ticker = function ticker(max) {
  let i = 0;
  let stop = false;
  Promise.resolve().then(function loop() {
    if (stop || i >= max) return;
    i++;
    Promise.resolve().then(loop);
  });
  return () => {
    stop = true;
    return i;
  };
};