Get rid of deprecated API where possible, add Channel.RENDEZVOUS
diff --git a/docs/basics.md b/docs/basics.md
index 30c4fdf..443a31f 100644
--- a/docs/basics.md
+++ b/docs/basics.md
@@ -115,7 +115,7 @@
the execution of the main function:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> { // start main coroutine
+fun main(args: Array<String>) = runBlocking { // start main coroutine
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L)
println("World!")
@@ -154,7 +154,7 @@
wait (in a non-blocking way) until the background [Job] that we have launched is complete:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = GlobalScope.launch { // launch new coroutine and keep a reference to its Job
delay(1000L)
println("World!")
@@ -194,7 +194,7 @@
in its scope complete. Thus, we can make our example simpler:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> { // this: CoroutineScope
+fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch { // launch new coroutine in the scope of runBlocking
delay(1000L)
println("World!")
@@ -217,7 +217,7 @@
while waiting for all children to complete.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> { // this: CoroutineScope
+fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
@@ -255,7 +255,7 @@
use other suspending functions, like `delay` in this example, to _suspend_ execution of a coroutine.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
launch { doWorld() }
println("Hello,")
}
@@ -281,7 +281,7 @@
[currentScope] builder comes to help: it inherits current [CoroutineScope] from the coroutine context it is invoked.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
launchDoWorld()
println("Hello,")
}
@@ -306,7 +306,7 @@
Run the following code:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
repeat(100_000) { // launch a lot of coroutines
launch {
delay(1000L)
@@ -329,7 +329,7 @@
returns from the main function after some delay:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
GlobalScope.launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/docs/cancellation-and-timeouts.md b/docs/cancellation-and-timeouts.md
index b2373f4..a026fd4 100644
--- a/docs/cancellation-and-timeouts.md
+++ b/docs/cancellation-and-timeouts.md
@@ -43,7 +43,7 @@
The [launch] function returns a [Job] that can be used to cancel running coroutine:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -85,7 +85,7 @@
example shows:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val startTime = System.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
@@ -129,7 +129,7 @@
Replace `while (i < 5)` in the previous example with `while (isActive)` and rerun it.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val startTime = System.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
@@ -169,7 +169,7 @@
finalization actions normally when coroutine is cancelled:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
try {
repeat(1000) { i ->
@@ -213,7 +213,7 @@
`withContext(NonCancellable) {...}` using [withContext] function and [NonCancellable] context as the following example shows:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
try {
repeat(1000) { i ->
@@ -256,7 +256,7 @@
Look at the following example:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
withTimeout(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -290,7 +290,7 @@
that is similar to [withTimeout], but returns `null` on timeout instead of throwing an exception:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val result = withTimeoutOrNull(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/docs/channels.md b/docs/channels.md
index 70a4614..adf89ed 100644
--- a/docs/channels.md
+++ b/docs/channels.md
@@ -56,7 +56,7 @@
a blocking `take` operation it has a suspending [receive][ReceiveChannel.receive].
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<Int>()
launch {
// this might be heavy CPU-consuming computation or async logic, we'll just send five squares
@@ -94,7 +94,7 @@
that all previously sent elements before the close are received:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<Int>()
launch {
for (x in 1..5) channel.send(x * x)
@@ -128,11 +128,11 @@
and an extension function [consumeEach], that replaces a `for` loop on the consumer side:
```kotlin
-fun CoroutineScope.produceSquares() = produce<Int> {
+fun CoroutineScope.produceSquares(): ReceiveChannel<Int> = produce {
for (x in 1..5) send(x * x)
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val squares = produceSquares()
squares.consumeEach { println(it) }
println("Done!")
@@ -165,7 +165,7 @@
In the below example the numbers are just squared:
```kotlin
-fun CoroutineScope.square(numbers: ReceiveChannel<Int>) = produce<Int> {
+fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = produce {
for (x in numbers) send(x * x)
}
```
@@ -173,7 +173,7 @@
The main code starts and connects the whole pipeline:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val numbers = produceNumbers() // produces integers from 1 and on
val squares = square(numbers) // squares integers
for (i in 1..5) println(squares.receive()) // print first five
@@ -238,7 +238,7 @@
the first ten prime numbers.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
var cur = numbersFrom(2)
for (i in 1..10) {
val prime = cur.receive()
@@ -370,7 +370,7 @@
(in this example we launch them in the context of the main thread as main coroutine's children):
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<String>()
launch { sendString(channel, "foo", 200L) }
launch { sendString(channel, "BAR!", 500L) }
@@ -457,7 +457,7 @@
```kotlin
data class Ball(var hits: Int)
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val table = Channel<Ball>() // a shared table
launch { player("ping", table) }
launch { player("pong", table) }
@@ -508,7 +508,7 @@
```kotlin
fun main(args: Array<String>) = runBlocking<Unit> {
- val tickerChannel = ticker(delay = 100, initialDelay = 0) // create ticker channel
+ val tickerChannel = ticker(delayMillis = 100, initialDelayMillis = 0) // create ticker channel
var nextElement = withTimeoutOrNull(1) { tickerChannel.receive() }
println("Initial element is available immediately: $nextElement") // initial delay hasn't passed yet
diff --git a/docs/exception-handling.md b/docs/exception-handling.md
index 9d024ac..e754bc3 100644
--- a/docs/exception-handling.md
+++ b/docs/exception-handling.md
@@ -300,8 +300,8 @@
}
try {
inner.join()
- } catch (e: JobCancellationException) {
- println("Rethrowing JobCancellationException with original cause")
+ } catch (e: CancellationException) {
+ println("Rethrowing CancellationException with original cause")
throw e
}
}
@@ -314,7 +314,7 @@
The output of this code is:
```text
-Rethrowing JobCancellationException with original cause
+Rethrowing CancellationException with original cause
Caught original java.io.IOException
```
<!--- TEST-->