Skip to content

Instantly share code, notes, and snippets.

@IQAndreas
Created January 22, 2012 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IQAndreas/1657551 to your computer and use it in GitHub Desktop.
Save IQAndreas/1657551 to your computer and use it in GitHub Desktop.
Progress for dynamic Task queue
//Users can add tasks at ANY time,
// but they are only removed after they are finished
var tasks:Vector.<Task>;
var currentTask:Task;
function nextTask():void
{
//Remove the first task from the list
currentTask = tasks.shift();
}
function get progress():Number
{
var numTasksRemaining:int = tasks.length; // Does not include the currently running task
return (currentTask.progress + numTasksRemaining) / (numTasksRemaining + 1);
}
@IQAndreas
Copy link
Author

How would you create a "progress" property for a task queue that is constantly added to, and removes the finished task when complete?

Assuming each task has a "progress property" (with Number 0 to 1) this snippet could work, and will update very well when new tasks are added. But if the "currentTask" is removed from the list (decrimenting 'numTasksRemaining') the progress bar will jump back and forward rather oddly.

(in this example, "numTasksRemaining" does NOT include the "currentTask")

Any suggestions for a better solution?

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