blob: 19ac2752cd2112dec42b01bdc692687533c0ec23 [file] [log] [blame]
Roman Elizarovf16fd272017-02-07 11:26:00 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovf16fd272017-02-07 11:26:00 +03003 */
4
Roman Elizarovb7721cf2017-02-03 19:23:08 +03005// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
Roman Elizarova9687a32018-06-29 17:28:38 +03006package kotlinx.coroutines.experimental.guide.channel08
Roman Elizarovb7721cf2017-02-03 19:23:08 +03007
8import kotlinx.coroutines.experimental.*
9import kotlinx.coroutines.experimental.channels.*
Roman Elizarov9fe5f462018-02-21 19:05:52 +030010import kotlin.coroutines.experimental.*
Roman Elizarovb7721cf2017-02-03 19:23:08 +030011
12fun main(args: Array<String>) = runBlocking<Unit> {
13 val channel = Channel<Int>(4) // create buffered channel
Roman Elizarov8b38fa22017-09-27 17:44:31 +030014 val sender = launch(coroutineContext) { // launch sender coroutine
Roman Elizarovb7721cf2017-02-03 19:23:08 +030015 repeat(10) {
16 println("Sending $it") // print before sending each element
17 channel.send(it) // will suspend when buffer is full
18 }
19 }
20 // don't receive anything... just wait....
21 delay(1000)
Roman Elizarov8b38fa22017-09-27 17:44:31 +030022 sender.cancel() // cancel sender coroutine
Roman Elizarovb7721cf2017-02-03 19:23:08 +030023}