This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CoroutineScope 확장함수 produceSquares 선언 | |
* : ReceiveChannel<Int>는 produce의 반환 인스턴스 | |
* : produce{} 블록 내부가 송신자(Sender)가 됨 | |
*/ | |
fun CoroutineScope.produceSquares(): ReceiveChannel<Int> = produce { | |
// 1~10까지 배수의 값을 전달 | |
for (i in 1..10) send(i * i) | |
} | |
fun main() = runBlocking { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.actor | |
import kotlin.system.measureTimeMillis | |
/* | |
* Sealed Class CounterMsg 정의 | |
* : Sealed class는 enum class의 확장판 개념 (enum은 상수들의 집합이라면 sealed는 클래스들의 집합) | |
* : Sealed Class는 모두 abstract(추상) 상태로 사용 시 구현이 필요 | |
* : 내부 클래스는 sealed class를 상속(extends) 필수, CounterMsg() | |
* */ |