Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d89b24

Browse files
Introduce guidance functions explaining 'launch' and 'async' usage (#4331)
Fixes KTIJ-13441
1 parent ec0d2c6 commit 2d89b24

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

‎kotlinx-coroutines-core/api/kotlinx-coroutines-core.api

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ public final class kotlinx/coroutines/GlobalScope : kotlinx/coroutines/Coroutine
378378
public fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext;
379379
}
380380

381+
public final class kotlinx/coroutines/GuidanceKt {
382+
public static final fun async (Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/Deferred;
383+
public static synthetic fun async$default (Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/Deferred;
384+
public static final fun launch (Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/Job;
385+
public static synthetic fun launch$default (Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/Job;
386+
}
387+
381388
public abstract interface annotation class kotlinx/coroutines/InternalCoroutinesApi : java/lang/annotation/Annotation {
382389
}
383390

‎kotlinx-coroutines-core/api/kotlinx-coroutines-core.klib.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ final fun <#A: kotlin/Any?> kotlinx.coroutines.flow/flowOf(kotlin/Array<out #A>.
925925
final fun <#A: kotlin/Any?> kotlinx.coroutines.flow/merge(kotlin/Array<out kotlinx.coroutines.flow/Flow<#A>>...): kotlinx.coroutines.flow/Flow<#A> // kotlinx.coroutines.flow/merge|merge(kotlin.Array<out|kotlinx.coroutines.flow.Flow<0:0>>...){0§<kotlin.Any?>}[0]
926926
final fun <#A: kotlin/Any?> kotlinx.coroutines/CompletableDeferred(#A): kotlinx.coroutines/CompletableDeferred<#A> // kotlinx.coroutines/CompletableDeferred|CompletableDeferred(0:0){0§<kotlin.Any?>}[0]
927927
final fun <#A: kotlin/Any?> kotlinx.coroutines/CompletableDeferred(kotlinx.coroutines/Job? = ...): kotlinx.coroutines/CompletableDeferred<#A> // kotlinx.coroutines/CompletableDeferred|CompletableDeferred(kotlinx.coroutines.Job?){0§<kotlin.Any?>}[0]
928+
final fun <#A: kotlin/Any?> kotlinx.coroutines/async(kotlin.coroutines/CoroutineContext = ..., kotlinx.coroutines/CoroutineStart = ..., kotlin.coroutines/SuspendFunction1<kotlinx.coroutines/CoroutineScope, #A>): kotlinx.coroutines/Deferred<#A> // kotlinx.coroutines/async|async(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.CoroutineStart;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>){0§<kotlin.Any?>}[0]
928929
final fun kotlinx.coroutines.channels/consumesAll(kotlin/Array<out kotlinx.coroutines.channels/ReceiveChannel<*>>...): kotlin/Function1<kotlin/Throwable?, kotlin/Unit> // kotlinx.coroutines.channels/consumesAll|consumesAll(kotlin.Array<out|kotlinx.coroutines.channels.ReceiveChannel<*>>...){}[0]
929930
final fun kotlinx.coroutines.sync/Mutex(kotlin/Boolean = ...): kotlinx.coroutines.sync/Mutex // kotlinx.coroutines.sync/Mutex|Mutex(kotlin.Boolean){}[0]
930931
final fun kotlinx.coroutines.sync/Semaphore(kotlin/Int, kotlin/Int = ...): kotlinx.coroutines.sync/Semaphore // kotlinx.coroutines.sync/Semaphore|Semaphore(kotlin.Int;kotlin.Int){}[0]
@@ -936,6 +937,7 @@ final fun kotlinx.coroutines/MainScope(): kotlinx.coroutines/CoroutineScope // k
936937
final fun kotlinx.coroutines/SupervisorJob(kotlinx.coroutines/Job? = ...): kotlinx.coroutines/CompletableJob // kotlinx.coroutines/SupervisorJob|SupervisorJob(kotlinx.coroutines.Job?){}[0]
937938
final fun kotlinx.coroutines/SupervisorJob0(kotlinx.coroutines/Job? = ...): kotlinx.coroutines/Job // kotlinx.coroutines/SupervisorJob0|SupervisorJob0(kotlinx.coroutines.Job?){}[0]
938939
final fun kotlinx.coroutines/handleCoroutineException(kotlin.coroutines/CoroutineContext, kotlin/Throwable) // kotlinx.coroutines/handleCoroutineException|handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){}[0]
940+
final fun kotlinx.coroutines/launch(kotlin.coroutines/CoroutineContext = ..., kotlinx.coroutines/CoroutineStart = ..., kotlin.coroutines/SuspendFunction1<kotlinx.coroutines/CoroutineScope, kotlin/Unit>): kotlinx.coroutines/Job // kotlinx.coroutines/launch|launch(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.CoroutineStart;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>){}[0]
939941
final inline fun <#A: kotlin/Any?, #B: kotlin/Any> (kotlinx.coroutines.flow/Flow<#A>).kotlinx.coroutines.flow/mapNotNull(crossinline kotlin.coroutines/SuspendFunction1<#A, #B?>): kotlinx.coroutines.flow/Flow<#B> // kotlinx.coroutines.flow/mapNotNull|mapNotNull@kotlinx.coroutines.flow.Flow<0:0>(kotlin.coroutines.SuspendFunction1<0:0,0:1?>){0§<kotlin.Any?>;1§<kotlin.Any>}[0]
940942
final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (kotlinx.coroutines.channels/BroadcastChannel<#A>).kotlinx.coroutines.channels/consume(kotlin/Function1<kotlinx.coroutines.channels/ReceiveChannel<#A>, #B>): #B // kotlinx.coroutines.channels/consume|consume@kotlinx.coroutines.channels.BroadcastChannel<0:0>(kotlin.Function1<kotlinx.coroutines.channels.ReceiveChannel<0:0>,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
941943
final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (kotlinx.coroutines.channels/ReceiveChannel<#A>).kotlinx.coroutines.channels/consume(kotlin/Function1<kotlinx.coroutines.channels/ReceiveChannel<#A>, #B>): #B // kotlinx.coroutines.channels/consume|consume@kotlinx.coroutines.channels.ReceiveChannel<0:0>(kotlin.Function1<kotlinx.coroutines.channels.ReceiveChannel<0:0>,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package kotlinx.coroutines
2+
3+
import kotlin.coroutines.CoroutineContext
4+
import kotlin.coroutines.EmptyCoroutineContext
5+
6+
/**
7+
* @suppress this is a function that should help users who are trying to use 'launch'
8+
* without the corresponding coroutine scope. It is not supposed to be called.
9+
*/
10+
@Deprecated("'launch' can not be called without the corresponding coroutine scope. " +
11+
"Consider wrapping 'launch' in 'coroutineScope { }', using 'runBlocking { }', " +
12+
"or using some other 'CoroutineScope'", level = DeprecationLevel.ERROR)
13+
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
14+
@kotlin.internal.LowPriorityInOverloadResolution
15+
public fun launch(
16+
context: CoroutineContext = EmptyCoroutineContext,
17+
start: CoroutineStart = CoroutineStart.DEFAULT,
18+
block: suspend CoroutineScope.() -> Unit
19+
): Job {
20+
throw UnsupportedOperationException("Should never be called, was introduced to help with incomplete code")
21+
}
22+
23+
/**
24+
* @suppress this is a function that should help users who are trying to use 'launch'
25+
* without the corresponding coroutine scope. It is not supposed to be called.
26+
*/
27+
@Deprecated("'async' can not be called without the corresponding coroutine scope. " +
28+
"Consider wrapping 'async' in 'coroutineScope { }', using 'runBlocking { }', " +
29+
"or using some other 'CoroutineScope'", level = DeprecationLevel.ERROR)
30+
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
31+
@kotlin.internal.LowPriorityInOverloadResolution
32+
public fun <T> async(
33+
context: CoroutineContext = EmptyCoroutineContext,
34+
start: CoroutineStart = CoroutineStart.DEFAULT,
35+
block: suspend CoroutineScope.() -> T
36+
): Deferred<T> {
37+
throw UnsupportedOperationException("Should never be called, was introduced to help with incomplete code")
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /