Channel 소수

    Coroutine Channels 2편 - Channel로 파이프라인 만들기, 파이프라인으로 소수 만들기

    Channel로 파이프라인 만들기 파이프라인은 하나의 Coroutine이 값의 스트림을 생성하는 것을 뜻한다. 값의 스트림은 무한할 수도 있다. fun CoroutineScope.produceNumbers() = produce { var x = 1 while (true) send(x++) // infinite stream of integers starting from 1 } 그리고 다른 Coroutine이나 Coroutines 들이 그 스트림을 소비하고, 작업을 수행하고, 다른 결과를 생성한다. 아래의 예시에서 숫자들은 단순히 제곱된다. fun CoroutineScope.square(numbers: ReceiveChannel): ReceiveChannel = produce { for (x in numbe..