If you call such a function, will not any idle time counter reset if one exists?
If you can outline the problem you are trying to solve, perhaps we can give you a hand. I can think of how I approach the solution of the “how much time has passed since the moment of this function” or “how much time has passed since the last event on the page” or “do something if the user has been on this page for X seconds" but I don’t have a good way to do this if nothing happened in X seconds. "
Update
Based on your update, I would look for a callback mechanism in the API (could you share what it is?) That will allow you to schedule some work after the API finishes. If this does not work, you can try adding something like:
setTimeout( function() { myCallbackMethod(); }, 0 );
This will cause your callback to begin after the current execution completes. It depends on the fact that the javascript mechanism is single-threaded, but I saw that it is used for a good effect.
source share