Skip to content

Commit a2d8088

Browse files
qwwdfsadelizarov
authored andcommitted
Get rid of deprecated API where possible, add Channel.RENDEZVOUS
1 parent 5633f91 commit a2d8088

File tree

103 files changed

+325
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+325
-310
lines changed

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,13 @@ public final class kotlinx/coroutines/experimental/channels/BroadcastKt {
716716
public abstract interface class kotlinx/coroutines/experimental/channels/Channel : kotlinx/coroutines/experimental/channels/ReceiveChannel, kotlinx/coroutines/experimental/channels/SendChannel {
717717
public static final field CONFLATED I
718718
public static final field Factory Lkotlinx/coroutines/experimental/channels/Channel$Factory;
719+
public static final field RENDEZVOUS I
719720
public static final field UNLIMITED I
720721
}
721722

722723
public final class kotlinx/coroutines/experimental/channels/Channel$Factory {
723724
public static final field CONFLATED I
725+
public static final field RENDEZVOUS I
724726
public static final field UNLIMITED I
725727
public final synthetic fun invoke (I)Lkotlinx/coroutines/experimental/channels/Channel;
726728
public static synthetic fun invoke$default (Lkotlinx/coroutines/experimental/channels/Channel$Factory;IILjava/lang/Object;)Lkotlinx/coroutines/experimental/channels/Channel;

common/kotlinx-coroutines-core-common/src/Annotations.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ package kotlinx.coroutines.experimental
1515
// todo: Experimental WARNING
1616
public annotation class ExperimentalCoroutinesApi
1717

18-
1918
/**
2019
* Marks declarations that are **obsolete** in coroutines API, which means that the design of the corresponding
21-
* declarations has serious known flaws and they must be redesigned in the future.
20+
* declarations has serious known flaws and they will be redesigned in the future.
2221
* Roughly speaking, these declarations will be deprecated in the future but there is no replacement for them yet,
2322
* so they cannot be deprecated right away.
2423
*/
@@ -36,4 +35,4 @@ public annotation class ObsoleteCoroutinesApi
3635
*/
3736
@Retention(value = AnnotationRetention.SOURCE)
3837
// todo: Experimental ERROR
39-
public annotation class InternalCoroutinesApi
38+
public annotation class InternalCoroutinesApi

common/kotlinx-coroutines-core-common/src/Delay.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import kotlin.coroutines.experimental.*
1919
*/
2020
@InternalCoroutinesApi // todo: Remove references from other docs
2121
public interface Delay {
22-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
22+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
2323
suspend fun delay(time: Long, unit: TimeUnit = TimeUnit.MILLISECONDS) = delay(time.convertToMillis(unit))
2424

2525
/**
@@ -33,7 +33,7 @@ public interface Delay {
3333
return suspendCancellableCoroutine { scheduleResumeAfterDelay(time, it) }
3434
}
3535

36-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
36+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
3737
fun scheduleResumeAfterDelay(time: Long, unit: TimeUnit, continuation: CancellableContinuation<Unit>) =
3838
scheduleResumeAfterDelay(time.convertToMillis(unit), continuation)
3939

@@ -54,7 +54,7 @@ public interface Delay {
5454
*/
5555
fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>)
5656

57-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
57+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
5858
fun invokeOnTimeout(time: Long, unit: TimeUnit, block: Runnable): DisposableHandle =
5959
DefaultDelay.invokeOnTimeout(time.convertToMillis(unit), block)
6060

@@ -69,7 +69,7 @@ public interface Delay {
6969
DefaultDelay.invokeOnTimeout(timeMillis, block)
7070
}
7171

72-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
72+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
7373
public suspend fun delay(timeMillis: Int) =
7474
delay(timeMillis.toLong(), TimeUnit.MILLISECONDS)
7575

common/kotlinx-coroutines-core-common/src/Scheduled.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package kotlinx.coroutines.experimental
77
import kotlinx.coroutines.experimental.selects.*
88
import kotlinx.coroutines.experimental.timeunit.*
99

10-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
10+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
1111
public suspend fun <T> withTimeout(time: Int, block: suspend CoroutineScope.() -> T): T =
1212
withTimeout(time.toLong(), block)
1313

@@ -39,7 +39,7 @@ public suspend fun <T> withTimeout(time: Int, block: suspend CoroutineScope.() -
3939
public suspend fun <T> withTimeout(time: Long, unit: TimeUnit = TimeUnit.MILLISECONDS, block: suspend CoroutineScope.() -> T): T =
4040
withTimeout(time.convertToMillis(unit), block)
4141

42-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
42+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
4343
public suspend fun <T> withTimeoutOrNull(time: Int, block: suspend CoroutineScope.() -> T): T? =
4444
withTimeoutOrNull(time.toLong(), TimeUnit.MILLISECONDS, block)
4545

common/kotlinx-coroutines-core-common/src/channels/Channel.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("FunctionName")
6+
57
package kotlinx.coroutines.experimental.channels
68

79
import kotlinx.coroutines.experimental.*
810
import kotlinx.coroutines.experimental.channels.Channel.Factory.CONFLATED
11+
import kotlinx.coroutines.experimental.channels.Channel.Factory.RENDEZVOUS
912
import kotlinx.coroutines.experimental.channels.Channel.Factory.UNLIMITED
10-
import kotlinx.coroutines.experimental.internal.*
1113
import kotlinx.coroutines.experimental.selects.*
1214

1315
/**
@@ -350,14 +352,17 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
350352
*/
351353
public companion object Factory {
352354
/**
353-
* Requests channel with unlimited capacity buffer in `Channel(...)` factory function --
354-
* the [LinkedListChannel] gets created.
355+
* Requests channel with unlimited capacity buffer in `Channel(...)` factory function
355356
*/
356357
public const val UNLIMITED = Int.MAX_VALUE
357358

358359
/**
359-
* Requests conflated channel in `Channel(...)` factory function --
360-
* the [ConflatedChannel] gets created.
360+
* Requests rendezvous channel in `Channel(...)` factory function -- the `RendezvousChannel` gets created.
361+
*/
362+
public const val RENDEZVOUS = 0
363+
364+
/**
365+
* Requests conflated channel in `Channel(...)` factory function -- the `ConflatedChannel` gets created.
361366
*/
362367
public const val CONFLATED = -1
363368

@@ -373,7 +378,7 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
373378
/**
374379
* Creates a channel without a buffer -- [RendezvousChannel].
375380
*/
376-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
381+
@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
377382
public fun <E> Channel(): Channel<E> = RendezvousChannel<E>()
378383

379384
/**
@@ -384,7 +389,7 @@ public fun <E> Channel(): Channel<E> = RendezvousChannel<E>()
384389
*/
385390
public fun <E> Channel(capacity: Int = 0): Channel<E> =
386391
when (capacity) {
387-
0 -> RendezvousChannel()
392+
RENDEZVOUS -> RendezvousChannel()
388393
UNLIMITED -> LinkedListChannel()
389394
CONFLATED -> ConflatedChannel()
390395
else -> ArrayChannel(capacity)

common/kotlinx-coroutines-core-common/src/channels/RendezvousChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import kotlinx.coroutines.experimental.*
2121
public open class RendezvousChannel<E>
2222
@Deprecated(
2323
"Replace with Channel factory function",
24-
replaceWith = ReplaceWith("Channel()")
24+
replaceWith = ReplaceWith("Channel(Channel.RENDEZVOUS)")
2525
)
2626
constructor() : AbstractChannel<E>() {
2727
protected final override val isBufferAlwaysEmpty: Boolean get() = true

common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class AsyncLazyTest : TestBase() {
1919
}
2020
expect(2)
2121
assertTrue(!d.isActive && !d.isCompleted)
22-
assertTrue(d.await() == 42)
22+
assertEquals(d.await(), 42)
2323
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
2424
expect(4)
25-
assertTrue(d.await() == 42) // second await -- same result
25+
assertEquals(d.await(), 42) // second await -- same result
2626
finish(5)
2727
}
2828

@@ -37,10 +37,10 @@ class AsyncLazyTest : TestBase() {
3737
}
3838
expect(2)
3939
assertTrue(!d.isActive && !d.isCompleted)
40-
assertTrue(d.await() == 42)
40+
assertEquals(d.await(), 42)
4141
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
4242
expect(5)
43-
assertTrue(d.await() == 42) // second await -- same result
43+
assertEquals(d.await(), 42) // second await -- same result
4444
finish(6)
4545
}
4646

@@ -66,7 +66,7 @@ class AsyncLazyTest : TestBase() {
6666
yield() // yield to second child (lazy async is not computing yet)
6767
expect(5)
6868
assertTrue(!d.isActive && !d.isCompleted)
69-
assertTrue(d.await() == 42) // starts computing
69+
assertEquals(d.await(), 42) // starts computing
7070
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
7171
finish(8)
7272
}
@@ -135,13 +135,13 @@ class AsyncLazyTest : TestBase() {
135135
yield() // yield to started coroutine
136136
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally) // and it finishes
137137
expect(5)
138-
assertTrue(d.await() == 42) // await sees result
138+
assertEquals(d.await(), 42) // await sees result
139139
finish(6)
140140
}
141141

142142
@Test
143143
fun testCancelBeforeStart() = runTest(
144-
expected = { it is JobCancellationException }
144+
expected = { it is CancellationException }
145145
) {
146146
expect(1)
147147
val d = async(start = CoroutineStart.LAZY) {
@@ -155,7 +155,7 @@ class AsyncLazyTest : TestBase() {
155155
assertTrue(!d.cancel())
156156
assertTrue(!d.start())
157157
finish(3)
158-
assertTrue(d.await() == 42) // await shall throw CancellationException
158+
assertEquals(d.await(), 42) // await shall throw CancellationException
159159
expectUnreached()
160160
}
161161

@@ -183,7 +183,7 @@ class AsyncLazyTest : TestBase() {
183183
assertTrue(d.cancel())
184184
assertTrue(!d.isActive && !d.isCompletedExceptionally && d.isCancelled) // still cancelling
185185
finish(6)
186-
assertTrue(d.await() == 42) // await shall throw CancellationException
186+
assertEquals(d.await(), 42) // await shall throw CancellationException
187187
expectUnreached()
188188
}
189189

common/kotlinx-coroutines-core-common/test/AsyncTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class AsyncTest : TestBase() {
232232
try {
233233
expect(1)
234234
deferred.await()
235-
} catch (e: JobCancellationException) {
235+
} catch (e: CancellationException) {
236236
finish(3)
237237
}
238238
}

common/kotlinx-coroutines-core-common/test/CancellableContinuationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CancellableContinuationTest : TestBase() {
8080
suspendCancellableCoroutine<Unit> { c ->
8181
continuation = c
8282
}
83-
} catch (e: JobCancellationException) {
83+
} catch (e: CancellationException) {
8484
expect(3)
8585
}
8686
}
@@ -105,7 +105,7 @@ class CancellableContinuationTest : TestBase() {
105105
suspendCancellableCoroutine<Unit> { c ->
106106
continuation = c
107107
}
108-
} catch (e: JobCancellationException) {
108+
} catch (e: CancellationException) {
109109
expect(3)
110110
}
111111
}

common/kotlinx-coroutines-core-common/test/CompletableDeferredTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
5+
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") // KT-21913
66

77
package kotlinx.coroutines.experimental
88

0 commit comments

Comments
 (0)