Learning Concurrency in Kotlin: Build highly efficient and robust applications by Miguel Angel Castiblanco Torres

Learning Concurrency in Kotlin: Build highly efficient and robust applications by Miguel Angel Castiblanco Torres

Author:Miguel Angel Castiblanco Torres [Castiblanco Torres, Miguel Angel]
Language: eng
Format: epub, pdf
Publisher: Packt Publishing
Published: 2018-07-29T23:00:00+00:00


delay(1200)

job.cancelAndJoin()

}

println("Took $duration ms")

}

This code will print "still running" every 500 milliseconds until the coroutine is cancelled; on cancellation the finally block will be executed. The main thread will be suspended for 1.2 seconds, then it will cancel the job and print the total execution time before ending the application:

As expected, the job was cancelled soon after the 1.2 seconds delay ended, and the finally printed the message. Now let's modify the finally so that it stalls for five seconds before actually letting the coroutine end:

} finally {

println("cancelled, will delay finalization now")

delay(5000)

println("delay completed, bye bye")

}

Now, upon execution, you'll notice that it doesn't work that way:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.