Repository navigation
Conversation
…ned scope Add asyncHandler, executorAsync and defaultExecutorAsync overloads that take a CoroutineScope, so cancelling that scope stops their coroutines. All async variants now report failures to Minestom's ExceptionManager instead of letting one failing handler cancel the scope it runs in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
asyncHandler,executorAsyncanddefaultExecutorAsynclaunch withCoroutineScope(context).launch, which creates a fresh scope nothing holds on to. Their coroutines can't be cancelled. In the example's/suspendingcommand, a player who quits mid-loop keeps getting messages sent for the remaining ~9 seconds, and a minigame that ends can't stop its handlers. Failures also skip Minestom'sExceptionManager.This adds an overload of each that takes the scope that owns the work:
All async variants, new and existing, now catch failures and report them to
ExceptionManager.handleException, the way Minestom's own listeners behave. Without that, one throwing handler would cancel a user's plain-Jobscope and silently kill every other handler running in it.Why not context parameters
A
context(scope: CoroutineScope)overload with the same name was the first idea. Testing showed Kotlin silently picks it whenever any scope is available, including insiderunBlocking { }orlaunch { }. That would quietly make existing handlers children of whatever coroutine registered them. An explicit parameter can't change existing call sites.Open questions (why this is a draft)
CoroutineContextoverloads. Removing them (breaking) would force every async handler to have an owner.ExceptionManager. That's arguably a fix, but it's a behavior change.Testing
CoroutineEventsTest: a failing handler leaves its scope active, and cancelling the scope cancels running handlers. With exception routing turned off, the first test fails, so it does guard the fix.compileKotlin,compileTestKotlinand:example:compileKotlinpass.