Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
refactor(Coroutine): Dispatch using executor instead of scheduler.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaRacci committed Dec 8, 2022
1 parent 9e31fb9 commit febb968
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package dev.racci.minix.core.coroutine.dispatcher

import arrow.core.toOption
import dev.racci.minix.api.coroutine.CoroutineTimings
import dev.racci.minix.api.extensions.scheduler
import dev.racci.minix.core.coroutine.service.WakeUpBlockService
import io.papermc.paper.util.MCUtil
import kotlinx.coroutines.CoroutineDispatcher
import org.bukkit.plugin.Plugin
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -32,14 +32,9 @@ internal class MinecraftCoroutineDispatcher(
context: CoroutineContext,
block: Runnable
) {
if (!plugin.isEnabled) {
println("Plugin isn't enabled, not dispatching")
return
}

context[CoroutineTimings.Key].toOption()
.tapNone { scheduler.runTask(plugin, block) }
.tapNone { MCUtil.MAIN_EXECUTOR.execute(block) }
.tap { timed -> timed.queue.add(block) }
.tap { timed -> scheduler.runTaskAsynchronously(plugin, timed) }
.tap { timed -> MCUtil.MAIN_EXECUTOR.execute(timed) }
}
}

0 comments on commit febb968

Please sign in to comment.