Skip to content

Instantly share code, notes, and snippets.

@peterbraden
Created August 30, 2010 18:38
Show Gist options
  • Save peterbraden/557826 to your computer and use it in GitHub Desktop.
Save peterbraden/557826 to your computer and use it in GitHub Desktop.
It would be nice to have a browser native delay function that added
a function to the call stack to be run immediately, but not blocking
UI, similar to
> setTimeout(func, 0).
Currently prototype does this - prototype.function.defer sets a
timeout of 0.01.
In my experience though, setting a timeout has a delay - Resig's
experiments seem to confirm:
> http://ejohn.org/blog/analyzing-timer-performance/
It'd be nice if
> window.defer(func)
was isomorphic to
> window.setTimeout(func, 0.01)
so that older browsers could be supported, but code ran much faster
with the defer code.
Is this a good idea? Is there a way to do this currently?
@peterbraden
Copy link
Author

Mr Boehmer,

Thanks - I hadn't realised Ben had investigated the delay.

I've played with worker threads, and whilst pretty cool, they're a hassle to implement because of the message passing.

The goal with this would be to stop the browser locking up on large loops - I find myself reimplementing the same chunk processing code and then trying to tune the timeout to be as quick as possible. Ideally I could just pass an iterable to a map function, and using this delay function it would ensure that the loop doesn't block the browser's thread.

So not as much background processing as splitting up foreground processing.

P

@peterbraden
Copy link
Author

Mr Boehmer,

Thanks - I hadn't realised Ben had investigated the delay.

I've played with worker threads, and whilst pretty cool, they're a hassle to implement because of the message passing.

The goal with this would be to stop the browser locking up on large loops - I find myself reimplementing the same chunk processing code and then trying to tune the timeout to be as quick as possible. Ideally I could just pass an iterable to a map function, and using this delay function it would ensure that the loop doesn't block the browser's thread.

So not as much background processing as splitting up foreground processing.

P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment