Shynixn / MCCoroutine

MCCoroutine is a library, which adds extensive support for Kotlin Coroutines for Minecraft Server environments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AsyncDispatcher behaves like Dispatchers.Unconfined

Spliterash opened this issue · comments

When I use asycnDispatcher it behaves like Dispatchers.Unconfined in every way, unless it is the main thread. Because of this, I caught a lot of errors, because I thought that he would always switch thread to the asynchronous bukkit, but it continued to execute in the lettuce thread, for example

Dispatch method from com.github.shynixn.mccoroutine.bukkit.dispatcher.AsyncCoroutineDispatcher

    override fun isDispatchNeeded(context: CoroutineContext): Boolean {
        wakeUpBlockService.ensureWakeup()
        return plugin.server.isPrimaryThread
    }

That's true and that's a limitation I have accepted when writing MCCoroutine.
I am not sure how to reliably detect if the current thread is one of the threads of the Bukkit async thread pool.

Solution is quite simple: Use Dispatchers.IO from Kotlin Coroutines. The asyncDispatcher can be seen more like convenient feaure. I also recommend to use Dispatchers.IO in the wiki.

Then please note it somehow in the documentation, because I didn't know about this limitation and I mistakenly dispatched my tasks to lettuce and mognoreactive

I'll leave this issue open to let myself know to improve the wiki regarding that.