public class GlobalScope implements CoroutineScope
A global interface CoroutineScope
not bound to any job.
Global scope is used to launch top-level coroutines which are operating on the whole application lifetime
and are not cancelled prematurely.
Another use of the global scope is operators running in Dispatchers.getUnconfined
, which don't have any job associated with them.
Application code usually should use application-defined interface CoroutineScope
, using
BuildersKt.async
or BuildersKt.launch
on the instance of class GlobalScope
is highly discouraged.
Usage of this interface may look like this:
fun ReceiveChannel.sqrt(): ReceiveChannel = GlobalScope.produce(Dispatchers.Unconfined) {
for (number in this) {
send(Math.sqrt(number))
}
}
Modifier and Type | Field and Description |
---|---|
static GlobalScope |
INSTANCE
A global
interface CoroutineScope not bound to any job. |
Modifier and Type | Method and Description |
---|---|
NonExistentClass |
getCoroutineContext()
Returns EmptyCoroutineContext.
|
getCoroutineContext
public static GlobalScope INSTANCE
A global interface CoroutineScope
not bound to any job.
Global scope is used to launch top-level coroutines which are operating on the whole application lifetime
and are not cancelled prematurely.
Another use of the global scope is operators running in Dispatchers.getUnconfined
, which don't have any job associated with them.
Application code usually should use application-defined interface CoroutineScope
, using
BuildersKt.async
or BuildersKt.launch
on the instance of class GlobalScope
is highly discouraged.
Usage of this interface may look like this:
fun ReceiveChannel.sqrt(): ReceiveChannel = GlobalScope.produce(Dispatchers.Unconfined) {
for (number in this) {
send(Math.sqrt(number))
}
}
public NonExistentClass getCoroutineContext()
Returns EmptyCoroutineContext.