본문 바로가기

Kotlin/10. Channel

(5)
10.4 Ticker Channel Ticker Channel public fun ticker( delayMillis: Long, initialDelayMillis: Long = delayMillis, context: CoroutineContext = EmptyCoroutineContext, mode: TickerMode = TickerMode.FIXED_PERIOD ): ReceiveChannel 인자로 주어진 시간마다 Channel로 Unit 값을 send Ticker는 RENDEZVOUS(랑데뷰) Channel 버퍼사이즈가 0 인 Channel Send 호출은 Receive 하기 전에 일시 중단 Receive 도 Send 하기 전에는 일시 중단 Ticker Mode TickerMode.FIXED_PERIOD 채널 지연이 생겨도 주어진..
10.3 Channel Pipelines / Fan-In, Fan-Out Channel Pipelines 나의 코루틴이 데이터 스트림 (무한 스트림 포함)을 생산해내고 다른 하나 이상의 코루틴들이 이 스트림을 수신 받아 필요한 작업을 수행 한 후 가공된 결과를 다시 전송하는 패턴 코루틴 파이프라인은 채널을 생성하여 서로 연속적으로 연결(필터링)하는 패턴 Fan-In 다수의 coroutine이 하나의 channel에 값을 receive 하는 것 Fan-Out 하나의 channel에 다수의 coroutine 을 send 하는 것
10.2 Buffered Channel Buffered Channel val channel = Channel(5) 디폴트 생성자를 통해 생성된 채널은 송신(생산자) 후 수신(소비자)자가 받 을 때 까지 기본적으로 정지된다( 하나씩 송신/수신) Channel 에 데이터를 담을 수 있는 버퍼의 개수를 정의할 수 있다 버퍼의 개수를 많이 해놓으면 빠른 처리 가능 그렇다고 비즈니스 로직보다 많이하면 ui가 업데이트 되지 않을 수 있음 Buffered Constant Channel.BUFFERED 버퍼를 64로 고정하며 65개 이상은 suspend 상태가 됨 Channel.CONFLATED 버퍼에서 처리 못한 item은 버리고 새것으로 대체 Channel.UNLIMITED 버퍼 사이즈를 메모리가 허락하는 한 무제한(메모리 부족 시 Runtime Err..
10.1 Channel이란 Channel interface SendChannel { suspend fun send(element: E) fun close(): Boolean } interface ReceiveChannel { suspend fun receive(): E } interface Channel : SendChannel, ReceiveChannel 코루틴 채널은 두 개이상의 코루틴 사이에 연결된 생산자와 소비자의 관계를 정의하는 것을 의미 Producer, Consumer Pattern SendChannel : 생산자 코루틴 채널 ReceiveChannel : 소비자 코루틴 채널 Deferred는 하나의 값만 반환 BlockQueue 와 유사하나 Channel 은 Non-Block BlockQueue put -> Chan..
10. Channel Channel 이란 Buffered Channel Channel Pipelines / Fan-In, Fan-Out Ticker Channel