Skip to content

feat(coroutines): add SchedulerDispatcher for any Minestom scheduler - #28

Merged
oglassdev merged 1 commit into
mainfrom
feat/scheduler-dispatcher
Oct 15, 2026
Merged

oglassdev merged 1 commit into
mainfrom
feat/scheduler-dispatcher

Conversation

@oglassdev

Copy link
Copy Markdown
Owner

Summary

  • Generalizes MinestomDispatcher into abstract class SchedulerDispatcher, which runs coroutines and counts tick-based delays on any Scheduler. MinestomDispatcher is now the instance for SchedulerManager and still looks the manager up lazily, so it's safe to reference before MinecraftServer.init().
  • Adds Scheduler.asCoroutineDispatcher() and Schedulable.asCoroutineDispatcher() (entities, players, instances).
  • Dispatchers are equal when they wrap the same scheduler (like kotlinx's executor dispatchers), so withContext between them doesn't add a tick.
  • KDoc warns that coroutines only resume while their scheduler is ticked. Coroutines on a removed entity's or unregistered instance's scheduler never resume.

Lifecycle-bound scopes (player.launch {} etc.) are intentionally out of scope; see the design review on the dead-owner/lifecycle problems.

Note: Scheduler extends Executor, so this shadows kotlinx's Executor.asCoroutineDispatcher() for Scheduler-typed receivers. That's intended: ours counts delays in ticks.

Verification

  • MinestomDispatcherTest: 5/5 pass. The new test checks that a custom scheduler's delay only advances when that scheduler ticks, and covers dispatcher equality.

@oglassdev
oglassdev merged commit 7a06dd6 into main Oct 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant