Tag: 协同进行

协程的行为是否正确?

我开始kotlin,不知道我已经正确实施了kotlin协程的生产者和消费者模式 ? @RestrictsSuspension interface Producer<in T> { suspend fun yield(value: T); } fun <T> produce(context: CoroutineContext = EmptyCoroutineContext, building: suspend Producer<T>.() -> Unit): Supplier<T> { val (NOT_READY, READY, DONE) = arrayOf(-1, 2, 3); val producer = object : Producer<T>, Continuation<Unit>, Supplier<T> { var value: T? = null; var step: Continuation<Unit>? = null; var state: Int […]