-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLOSED] Add process in background options to doSequentially #1003
Comments
Comment by peterflynn Very interesting! A few questions/comments:
|
Comment by peterflynn 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? |
Comment by jhatwich 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 <
|
Comment by jhatwich 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.
|
Comment by peterflynn
|
Issue by jhatwich
Thursday Jun 07, 2012 at 12:57 GMT
Originally opened as adobe/brackets#1009
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.
jhatwich included the following code: https://github.com/adobe/brackets/pull/1009/commits
The text was updated successfully, but these errors were encountered: