-
-
Notifications
You must be signed in to change notification settings - Fork 1
Coroutines
Nexus employs native Java threads (system threads) internally to manage various tasks using its dedicated thread pool. While this approach is effective, an alternative with potential benefits exists. Kotlin introduces its own coroutine system, accessible exclusively to Kotlin users. However, to ensure compatibility with Java developers, we do not employ this system by default. Nevertheless, we recognize the advantages of Kotlin's coroutine technology and have introduced our custom async wrapper.
The Nexus Launch serves as our proprietary async wrapper, granting developers the ability to encompass Nexus' internal async processes (such as event handling) with alternative, more cost-effective solutions. By adjusting Nexus' configuration, you can employ a distinct async mechanism (please note that in this example, we use GlobalScope
, but we recommend using your personal CoroutineScope
):
Nexus.configure {
launch.launcher = NexusLaunchWrapper { task ->
GlobalScope.launch { task.run() }
}
launch.scheduler = NexusScheduledLaunchWrapper { timeInMillis, task ->
return@NexusScheduledLaunchWrapper object : Cancellable {
val job = GlobalScope.launch {
delay(timeInMillis)
task.run()
}
override fun cancel(mayInterruptIfRunning: Boolean): Boolean {
job.cancel()
return true
}
}
}
}
From a performance perspective, this adjustment typically yields no substantial or easily discernible impact. However, if you perceive a difference or are curious, consider implementing and evaluating a similar solution. While this alteration may not deliver significant gains, it similarly poses no drawbacks. Feel free to experiment with this approach as needed.
All information in this wiki was written during v1.2.0
, we recommend updating to that version if you are below, or creating an issue in GitHub, updating the wiki if the current information is missing, outdated or lacking.
To get started with Nexus, we recommend reading the following in chronological:
- Installation & Preparing Nexus
- Designing Commands
- Command Interceptors
- Additional Features (Subcommand Router, Option Validation)
- Context Menus
- Command Synchronization
You may want to read a specific part of handling command and middleware responses:
You can also read about additional features of Nexus:
- Subcommand Routing
- Option Validation
- Express Way (shard management)
- Inheritance
- Feather Pagination
- Nexus.R
You can read about synchronizing commands to Discord:
For more additional performance:
Additional configurations: