Added a coroutine dispatcher for server thread#14
Conversation
Glease
left a comment
There was a problem hiding this comment.
Need more documentation: please specify the exact timing of coroutine running (pre server tick? post?), or explicitly state it's unspecified and ask the caller to not rely on this detail
|
The running timing depends on how GTNHLib implements this. But should I add this info to the doc? I mean if the GTNHLib implementation changes, this can be inaccurate. |
|
Then perhaps state "The exact moment when your coroutine will be run is determined by GTNHLib. As of writing this is xxxxx". Besides, your code seem to run the coroutine directly if it's on main thread already, without asking GTNHLib at all. This is not reflected in documentation or your comment at all. |
This feature requires GTNHLib to be installed (but optional, so that mods not using this feature are ok without GTNHLib).
This is used for mods using coroutines where they want to switch context (thread) to the server thread.
For example, I can launch a background coroutine, looping and setting the block at 0, 0, 0 to air. To prevent weird bugs caused by not doing it in the server thread, I can now use
withContext(Dispatchers.MinecraftServer) { world.setBlockToAir(0, 0, 0) }to fix this.For more details, see the Kotlin Coroutines documents.