草庐IT

produceSquares

全部标签

kotlin - CoroutineScope 背后的概念是什么?

看完CoroutineScope的介绍和javadoc我仍然有点困惑CoroutineScope背后的想法是什么。文档的第一句话“定义新协程的范围”。我不清楚:为什么我的协程需要范围?另外,为什么不推荐使用独立的协程构建器?为什么这样做更好:funCoroutineScope.produceSquares():ReceiveChannel=produce{for(xin1..5)send(x*x)}而不是funproduceSquares():ReceiveChannel=produce{//nolongeranextensionfunctionfor(xin1..5)send(x*x

kotlin - CoroutineScope 背后的概念是什么?

看完CoroutineScope的介绍和javadoc我仍然有点困惑CoroutineScope背后的想法是什么。文档的第一句话“定义新协程的范围”。我不清楚:为什么我的协程需要范围?另外,为什么不推荐使用独立的协程构建器?为什么这样做更好:funCoroutineScope.produceSquares():ReceiveChannel=produce{for(xin1..5)send(x*x)}而不是funproduceSquares():ReceiveChannel=produce{//nolongeranextensionfunctionfor(xin1..5)send(x*x