小编kok*_*tin的帖子

kotlin 协程多次启动

如何在kotlin中像多线程一样进行多次启动

我想让它first second永远同时工作!!

像这段代码...

runBlocking {

    // first
    launch{
      first()
    }

    // second
    launch{
       second()
    }
}


suspend fun first(){
    // do something 
    delay(1000L)

    // Recursive call
    first() 
}

suspend fun second(){
    // do something 
    delay(1000L)

    // Recursive call
    second() 
}
Run Code Online (Sandbox Code Playgroud)

coroutine kotlin kotlin-coroutines

3
推荐指数
1
解决办法
1998
查看次数

标签 统计

coroutine ×1

kotlin ×1

kotlin-coroutines ×1