``` import nl.komponents.kovenant.task import nl.k...
# kovenant
n
Copy code
import nl.komponents.kovenant.task
import nl.komponents.kovenant.then

fun main(args: Array<String>) {
    var counter = 40;

    task {
        while (counter != 0) {
            println("Active threads: ${Thread.activeCount()}")
            Thread.sleep(200)
        }
    }

    for (i in 1..40) {
        task {
            val duration = Math.random() * 500 + 500
            Thread.sleep(duration.toLong())

            i
        } then {
            println("Thread ${it} finished")
            synchronized(counter) {
                counter--
            }
        }
    }
}