Created
January 22, 2012 16:15
-
-
Save IQAndreas/1657551 to your computer and use it in GitHub Desktop.
Progress for dynamic Task queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?