-
Notifications
You must be signed in to change notification settings - Fork 1
Description
No root cause found yet and the problem is a bit puzzling. AFAICS there are situations which are hard to diagone in where it does not work properly. It just does not (never) invoke the fn() again. Looks like something is blocking the further calls.
once_per_cycle(fn, ...args) is supposed to work basically as follows:
let t;
clearTimeout(t);
t = setTimeout(fn, 0, ...args);
Note that this basically is the working replacement.
However with some benefits:
- It always is executed delayed, so the function always is async. (I am not yet completely sure about this, have to analyse my code again in detail. This certainly should be an option.)
- The first invocation should be run more early (I am not yet completely sure about this, have to analyse my code again in detail. This certainly should be an option.)
- Only the last invocation is executed, so all other invocations (as seen above) are automatically cancelled (and the
...argsare returned). - While function
fnis executing (async), a single recursion is possible! - All further recursions shall be prohibited (and reported in the console).
.. and possibly a bit more. (I am not yet completely sure about this, have to analyse my code again in detail. This certainly should be an option.)
And ..
.. it should be better documented, so that I am no puzzling myself. So here is the plan (dunno how long this will take):
- Find out what is going wrong.
- From what I had seen (in some private code) create an example which presents the problem (difficult!)
- Find out what's wrong.
- If previous is too difficult (likely) re-create the code from scratch
- With a bit more bells and whistles!
- But much cleaner than the current code!
- Mostly compatible to the spirit of the present code
So it is likely the second variant I need to do. But this will take time ..