Job

A job is a fire-and-forget task. An operation that, once started, you will not be waiting on, unless, maybe, there's an exception. The most common way to create a job is to use the launch() coroutine builder, as shown:

fun main(args: Array<String>) = runBlocking {
val job = launch {
// Do background task here
}
}

However, you can also use the Job() factory function, like this:

fun main(args: Array<String>) = runBlocking {
val job = Job()
}
Job is an interface, and both launch() and Job() return the JobSupport implementation, which is the basis of many implementations of Job. Deferred—which we will see as we move aheadis an interface that extends Job.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.123.73