Whenever your application has several things to do, you need to figure out how to schedule those things. This episode explains a common technique called a round robin that gives everything a fair share.
Let’s say that you have multiple tasks you want to manage and track yourself in your application. What kind of tasks?
- Your application might allow users to place markers on topics the user find interesting and notify the user whenever any changes occur to those topics.
- Your application might monitor the performance of some object or process and notify the user of any irregularities. the user could select multiple things to monitor.
- Your application has it’s own tasks it needs to do periodically. Maybe it needs to check for updates so the user is automatically running the latest version.
Whatever you need to do, if you have a list of these tasks and you need to make progress on all of them, then a round robin is a good technique. It’s a simple approach, just start with the first item, advance to the next either when the first task is done or after some predetermined time or amount of progress. Then move to the next item and do the same thing. After all the tasks have been given a turn, go back to the first task.
You need to manage the switching of tasks yourself. And this needs to be done from within the task. For a long running task, just make sure to check every now and then if a switch should be made.