Hello, I'm currently working with a `CoroutineCont...
# coroutines
r
Hello, I'm currently working with a
CoroutineContext
with two exception handlers: one that is mine, and one from a different library (inlined hidden impl) which I'm trying to both remove to add a new one. Currently doing this:
Copy code
override val coroutineContext: CoroutineContext get() = syncContext
    .minusKey(CoroutineExceptionHandler)
    .minusKey(CoroutineExceptionHandler)
    .plus(GameInstanceExceptionHandler(this))
But I'm still getting the one hidden exception handler in the context. Here's what happens when I print it:
Copy code
[com.github.shynixn.mccoroutine.bukkit.impl.CoroutineSessionImpl$special$$inlined$CoroutineExceptionHandler$1@5e90d7d5, net.radsteve.axi.game.instance.GameInstanceExceptionHandler@47f46d1f, net.radsteve.axi.event.CurrentlyCalledEvent@332cca3, kotlinx.coroutines.UndispatchedMarker@b19f379, UndispatchedCoroutine{Active}@2d6e9d46, MinecraftCoroutineDispatcher@6a486f9c]
How can I remove this first exception handler in here?
I could probably just fold the context, starting with my exception handler and then adding any other elements that are not exception handlers, right? Will try that later
Copy code
override val coroutineContext: CoroutineContext by lazy {
    syncContext.fold(GameInstanceExceptionHandler(this) as CoroutineContext) { acc, elem ->
      if (elem.key == CoroutineExceptionHandler) {
        acc
      } else {
        acc + elem
      }
    }
  }
This works, but I'm calling
withContext
with this context on an existing coroutine context with another context element I don't want. Is there any way to prevent it from merging?
I figured that out too by creating a new coroutine scope and launching with a specified context