07-04 04:05
Notice
Recent Posts
Recent Comments
07-04 04:05
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

pear

[kotlin] event interface channel 활용 본문

android/kotlin

[kotlin] event interface channel 활용

pearlab 2023. 5. 24. 13:14

비동기 처리에서 listener(callback event)의 관리를 simaple 하게 하기 위해 react, rx 등을 사용하고 있다

 

kotlin에서는 channel을 제공하고 있다.

기본적으로 send와 receive를 지원하며 blocking queue event라고 생각 하면 이해에 도움이 될거 같다.

coroutine을 사용하여 비동기로 사용할 수 있다.

 

trysend는 receive가 queue가 full이면  fail 처리 된다.

send처럼 receive의 quque가 full이면 suspends되어 대기 한다.

 

rx의 hot obserable과 유사한 개념을 가지고 있지만 기본적인 동작은 queue이다.

trysend overflow option을 사용해서 유사하게 처리 할수 있을 것 같다.

 

send & trysend & optional을 잘 조합하여 서비스에 맞는 이벤트 처리를 하면 되겠다.

 

 

https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/