, 是可以取消的 ;
在 Flow#collect 代码块中 , 执行 Job#cancel 函数 , 即可 取消该流收集操作所在的协程 , 进而取消了流 ;
/**
* 用一个可选的cancel..., 收集几个元素后 , 执行 Flow#cancel 函数 , 取消流收集所在协程 ;
package kim.hsl.coroutine
import android.os.Bundle
import...if (it == 2) {
// 收集到元素 2 时, 取消流
// 在流中 emit...$it")
// 收集到元素 2 时, 协程退出
if (it == 2) {
cancel(...().cancellable().collect {
println("收集到元素 $it")
// 收集到元素 2 时, 协程退出