launch

fun <ERROR CLASS>.launch(context: CoroutineContext = velocityDispatcher, start: <ERROR CLASS> = CoroutineStart.DEFAULT, block: suspend <ERROR CLASS>.() -> Unit): <ERROR CLASS>

Launches a new coroutine on the Velocity Plugin ThreadPool without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is Job.cancel.

The coroutine context is inherited from a PluginContainer.scope. Additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then PluginContainer.velocityDispatcher is used. The parent job is inherited from a PluginContainer.scope as well, but it can also be overridden with a corresponding context element.

By default, the coroutine is scheduled on the Velocity thread pool which is executed later. Other start options can be specified via start parameter. See CoroutineStart for details. An optional start parameter can be set to CoroutineStart.LAZY to start coroutine lazily. In this case, the coroutine Job is created in new state. It can be explicitly started with Job.start function and will be started implicitly on the first invocation of Job.join.

Uncaught exceptions in this coroutine do not cancel the parent job or any other child jobs. All uncaught exceptions are logged to the plugin logger. by default.

Parameters

context

The coroutine context to start. Should almost be always be PluginContainer.velocityDispatcher. Async operations should be be created using withContext after using the default parameters of this method.

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

block

the coroutine code which will be invoked in the context of the provided scope.