Coroutine Integration
Axi provides great coroutine integration to Minecraft using MCCoroutine ↗.
WARNING
Do not shade your own version of kotlinx.coroutines
. This may break Axi as it relies on IntelliJ's internal fork of kotlinx.coroutines
and leverages some of its internal coroutine API.
Extensions
Axi adds the following extensions:
AxiPlugin.coroutineScope
: The coroutine scope of the pluginAxiPlugin.syncContext
: The synchronously executed coroutine context of the plugin, with an exception handler that prints stack traces for coroutine exceptionsAxiPlugin.asyncContext
: The asynchronously executed coroutine context of the plugin, with an exception handler that prints stack traces for coroutine exceptionsAxiPlugin.sync
: Launches a synchronously executed jobAxiPlugin.async
: Launches an asynchronously executed jobAxiPlugin.syncContext()
: Switches to theAxiPlugin.syncContext
AxiPlugin.asyncContext()
: Switches to theAxiPlugin.asyncContext
All of these exist for the main plugin as well with the AxiCoroutines
object.
Suspending Events
You can register event handlers with suspending handler functions using AxiPlugin.registerEventListeners
.
There is also another utility provided by Axi: SuspendingListener
, an interface that implements Listener
and is a synchronous CoroutineScope
. This is useful if you want to launch jobs in your events.