-
Notifications
You must be signed in to change notification settings - Fork 1
Platform: TaskManager
Dani ツ edited this page Jun 1, 2025
·
1 revision
PlatformTaskManager provides a simple abstraction for scheduling tasks either synchronously or asynchronously on the underlying platform, with optional delayed execution based on server ticks.
| Method | Description |
|---|---|
scheduleSync(task: Runnable) |
Schedule a task to run synchronously immediately. |
scheduleDelayedSync(delayTicks: Int, task: Runnable) |
Schedule a synchronous task with a delay (in ticks). |
scheduleAsync(task: Runnable) |
Schedule a task to run asynchronously immediately. |
scheduleDelayedAsync(delayTicks: Int, task: Runnable) |
Schedule an asynchronous task with a delay (in ticks). |
AsyncPlatformTaskManager uses Java's ExecutorService and ScheduledExecutorService to handle async and delayed tasks off the main thread:
val taskManager = AsyncPlatformTaskManager.taskManager("my-extension")
taskManager.scheduleAsync { println("async task") }
taskManager.scheduleDelayedSync(20) { println("delayed sync task") }Details: AsyncPlatformTaskManager.kt
For Bukkit-based platforms, BukkitPlatformTaskManager uses the native Bukkit scheduler:
val taskManager = BukkitPlatformTaskManager.taskManager(plugin)
taskManager.scheduleSync { /* sync code */ }
taskManager.scheduleDelayedAsync(10) { /* async delayed code */ }Details: BukkitPlatformTaskManager.kt
taskManager.scheduleSync {
println("Runs immediately on main thread")
}
taskManager.scheduleDelayedAsync(40) {
println("Runs async after 40 ticks delay")
}You can implement your own
PlatformTaskManagerto adapt to different threading or scheduling models as needed for your platform.
Anything unclear or inaccurate? Please let it know by creating an issue.