Channel
interface SendChannel<E> {
suspend fun send(element: E)
fun close(): Boolean
}
interface ReceiveChannel<E> {
suspend fun receive(): E
}
interface Channel<E> : SendChannel<E>, ReceiveChannel<E>
- 코루틴 채널은 두 개이상의 코루틴 사이에 연결된 생산자와 소비자의 관계를 정의하는 것을 의미
- Producer, Consumer Pattern
- SendChannel : 생산자 코루틴 채널
- ReceiveChannel : 소비자 코루틴 채널
- Deferred는 하나의 값만 반환
- BlockQueue 와 유사하나 Channel 은 Non-Block
- BlockQueue put -> Channel send()
- BlockQueue take -> Channel receive()
- 채널은 수신을 하지 않아도 무조건 보냄(Hot Stream)
'Kotlin > 10. Channel' 카테고리의 다른 글
10.4 Ticker Channel (0) | 2023.11.01 |
---|---|
10.3 Channel Pipelines / Fan-In, Fan-Out (0) | 2023.11.01 |
10.2 Buffered Channel (0) | 2023.11.01 |
10. Channel (0) | 2023.11.01 |