Add support for an advanced task scheduler managed by the application.

I left the basic logic there, as it feels like one of the better ways for delay consistency between timeout and scheduler, but I refactored the code so that the task shifting doesn't happen until a point where we know we want to remove the task. I hope this is a bit clearer.