The current implementation only keeps the scheduler alive while there are tasks to run, meaning that a spinning task must be added to keep it from terminating. Instead, the scheduler should continue to look for pending tasks and give up execution by sleeping for a few hundred microseconds whenever none are scheduled. This process should only stop when the scheduler is canceled explicitly by the user.
The current implementation only keeps the scheduler alive while there are tasks to run, meaning that a spinning task must be added to keep it from terminating. Instead, the scheduler should continue to look for pending tasks and give up execution by sleeping for a few hundred microseconds whenever none are scheduled. This process should only stop when the scheduler is canceled explicitly by the user.