Skip to content

Commit c9d079e

Browse files
committed
Add paragraph about parent cancellation to async.
Mention structured concurrency, but do not explain it there as the term should be easily googlable Fixes #787
1 parent 5a6aa6c commit c9d079e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public fun CoroutineScope.launch(
6060
/**
6161
* Creates a coroutine and returns its future result as an implementation of [Deferred].
6262
* The running coroutine is cancelled when the resulting deferred is [cancelled][Job.cancel].
63+
* The resulting coroutine has a key difference compared with similar primitives in other languages
64+
* and frameworks: it cancels the parent job (or outer scope) on failure to enforce *structured concurrency* paradigm.
65+
* To change that behaviour, supervising parent ([SupervisorJob] or [supervisorScope]) can be used.
6366
*
6467
* Coroutine context is inherited from a [CoroutineScope], additional context elements can be specified with [context] argument.
6568
* If the context does not have any dispatcher nor any other [ContinuationInterceptor], then [Dispatchers.Default] is used.
@@ -72,8 +75,6 @@ public fun CoroutineScope.launch(
7275
* the resulting [Deferred] is created in _new_ state. It can be explicitly started with [start][Job.start]
7376
* function and will be started implicitly on the first invocation of [join][Job.join], [await][Deferred.await] or [awaitAll].
7477
*
75-
* @param context additional to [CoroutineScope.coroutineContext] context of the coroutine.
76-
* @param start coroutine start option. The default value is [CoroutineStart.DEFAULT].
7778
* @param block the coroutine code.
7879
*/
7980
public fun <T> CoroutineScope.async(

0 commit comments

Comments
 (0)