-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add process in background options to doSequentially #1009
Conversation
Do sequentially can now be used to process a list of tasks in time slices so long-running processes don't block up the UI.
Very interesting! A few questions/comments:
|
Here's an example of the notion of building this API on top of doSequentially() instead of integrated into it. (I haven't tested this code at all yet, so caveat emptor). function doInBackground(items, processItem, maxBlockingTime, idleTime) {
// Argument defaults
maxBlockingTime = maxBlockingTime || 20;
idleTime = idleTime || 30;
var sliceStartTime = (new Date()).getTime();
return doSequentially(items, function (item, i) {
var result = new $.Deferred();
processItem(item, i);
// If our time slice is done, pause before letting the next item in the sequence begin
// processing. If we still have more time left, let the next item start immediately.
if ((new Date()).getTime() - sliceStartTime >= maxBlockingTime) {
window.setTimeout(function () {
sliceStartTime = (new Date()).getTime();
result.resolve();
}, idleTime);
} else {
result.resolve();
}
return result;
}, false);
} What do you think? Does this remain flexible enough for your (and similar) needs? |
Making it a separate API would work fine for my needs - the optional Exposing idleTime and maxBlockingTime is a good idea too. The sliceNow option allows you to try to get something done sync, but defer
On Fri, Jun 8, 2012 at 5:35 PM, Peter Flynn <
|
Restore doSequentially to process the list in a blocking fashion and add doSequentiallyInBackground that does processing in configurable time slices.
Sorry for the long delay. I've finally applied the refactoring to Async based on your code and it seem to be working great. I left delayStartTime out for now since I'm not using it anyway.
|
@jhatwich: Sorry for my long delay as well :-) It looks good to me -- merging now. |
Add Async utility for background processing
Do sequentially can now be used to process a list of tasks in time
slices so long-running processes don't block up the UI.
I ran into the need for this in creating a related files extension.