Once a state has been reached, a job will not move back to a previous state. Consider the following application:
fun main(args: Array<String>) = runBlocking {
val time = measureTimeMillis {
val job = launch {
delay(2000)
}
// Wait for it to complete once
job.join()
// Restart the Job
job.start()
job.join()
}
println("Took $time ms")
}
This code creates a job that suspends execution for 2 seconds. Once the job completes on the first call to job.join(), the start() function is called on job with the intent of restarting it, followed by a second call to join() to wait for the second execution to complete. The complete time of execution was measured and stored in the time variable.
Let's see how long the execution of this code takes:
As you can see, the...