Closed ahmedre closed 4 weeks ago
isActive
is true
whenever the coroutine is neither canceled
nor complete
.
Before this fix, if addListener
is called before setSimulatedRoute
, the job will run, find the start and next state as the same, and therefore assume the simulation is done. The coroutine is marked as complete
, and when setSimulatedRoute
is called, nothing happens. By checking the state of the coroutine, we allow re-running this when setSimulatedRoute
is called, whenever the actual job is complete (or hasn't been set or has been canceled).
There's also no way to "stop" the job without making it run all the way through at the moment, so maybe we should also add some cancelation call at some point to stop the simulation.
Instead of determining whether or not to start the simulation based on whether or not the job is null, instead, use the active state of the job to determine whether or not to start the simulator. This allows the SimulatedLocationProvider to be reused more than once, and also allows for addListener to happen before setSimulatedRoute is called without breaking the simulation.