https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

mcastiblanco

01/15/2018, 2:33 AM
@eddy_wm here is a simple example of it
Copy code
fun main(args: Array<String>) = runBlocking{
    val dispatcher = newFixedThreadPoolContext(10, "myPool")

    val jobs = ArrayList<Job>()
    for (i in 1..10) {
        jobs.add(launch(dispatcher) {
            println("Running in ${Thread.currentThread().name}")
            Thread.sleep(2000)
        })
    }

    for (job in jobs) {
        job.join()
    }
}
which then prints something like
Copy code
Running in myPool-1
Running in myPool-2
Running in myPool-3
Running in myPool-4
Running in myPool-5
Running in myPool-6
Running in myPool-7
Running in myPool-8
Running in myPool-9
Running in myPool-10
4 Views