At what points in the control flow of an inner function can an outer event listener be triggered

Take the following function:

export function repeater(): void {
  let timeout: number | undefined = undefined;
  const repeat = () => {
    some_slow_func();
    timeout = setTimeout(repeat, 100);
  };
  repeat();
  document.addEventListener('mouseup', () => clearTimeout(timeout), { once: true });
}

When the user releases their mouse, is it possible for clearTimeout to run, but only for timeout to be reset by the setTimeout line? E.g., say the user releases their mouse while some_slow_func() is running. I’ve played around with it and the answer seems to be that the event functionality will only be processed during a timeout, but I’d like to know why (and if this is actually correct).