-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
shynixn
committed
Oct 3, 2024
1 parent
01b85bd
commit 968ca36
Showing
25 changed files
with
465 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
repositories { | ||
maven { | ||
url = uri("https://repo.papermc.io/repository/maven-public/") | ||
} | ||
} | ||
|
||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
} | ||
|
||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":mccoroutine-folia-api")) | ||
|
||
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9") | ||
compileOnly("dev.folia:folia-api:1.20.1-R0.1-20230615.235213-1") | ||
|
||
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9") | ||
testImplementation("dev.folia:folia-api:1.20.1-R0.1-20230615.235213-1") | ||
} |
13 changes: 13 additions & 0 deletions
13
...ine-folia-test/src/main/java/com/github/shynixn/mccoroutine/folia/test/TestMCCoroutine.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.shynixn.mccoroutine.folia.test | ||
|
||
import com.github.shynixn.mccoroutine.folia.test.impl.TestMCCoroutineImpl | ||
|
||
interface TestMCCoroutine { | ||
companion object { | ||
/** | ||
* The driver to load the test implementation of MCCoroutine. | ||
* Useful for UnitTests. | ||
*/ | ||
val Driver = TestMCCoroutineImpl::class.java.name | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../java/com/github/shynixn/mccoroutine/folia/test/dispatcher/TestMainCoroutineDispatcher.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.shynixn.mccoroutine.folia.test.dispatcher | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Runnable | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
internal class TestMainCoroutineDispatcher : CoroutineDispatcher() { | ||
private val threadPool: ExecutorService = Executors.newFixedThreadPool(1) | ||
var threadId: Long? = null | ||
|
||
init { | ||
threadPool.submit { | ||
Thread.currentThread().name = "[PluginMainThread]" | ||
threadId = Thread.currentThread().id | ||
} | ||
} | ||
|
||
override fun isDispatchNeeded(context: CoroutineContext): Boolean { | ||
return Thread.currentThread().id != threadId | ||
} | ||
|
||
override fun dispatch(context: CoroutineContext, block: Runnable) { | ||
threadPool.submit { | ||
block.run() | ||
} | ||
} | ||
|
||
fun dispose() { | ||
threadPool.shutdown() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...m/github/shynixn/mccoroutine/folia/test/dispatcher/TestMultiThreadsCoroutineDispatcher.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.shynixn.mccoroutine.folia.test.dispatcher | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
internal class TestMultiThreadsCoroutineDispatcher(private val name : String) : | ||
CoroutineDispatcher() { | ||
private val threadPool: ExecutorService = Executors.newFixedThreadPool(4) | ||
|
||
override fun isDispatchNeeded(context: CoroutineContext): Boolean { | ||
return true | ||
} | ||
|
||
override fun dispatch(context: CoroutineContext, block: Runnable) { | ||
threadPool.submit { | ||
Thread.currentThread().name = name | ||
block.run() | ||
} | ||
} | ||
|
||
fun dispose() { | ||
threadPool.shutdown() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../github/shynixn/mccoroutine/folia/test/dispatcher/TestSingleThreadsCoroutineDispatcher.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.shynixn.mccoroutine.folia.test.dispatcher | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
internal class TestSingleThreadsCoroutineDispatcher(private val name : String) : | ||
CoroutineDispatcher() { | ||
private val threadPool: ExecutorService = Executors.newFixedThreadPool(1) | ||
|
||
override fun isDispatchNeeded(context: CoroutineContext): Boolean { | ||
return true | ||
} | ||
|
||
override fun dispatch(context: CoroutineContext, block: Runnable) { | ||
threadPool.submit { | ||
Thread.currentThread().name = name | ||
block.run() | ||
} | ||
} | ||
|
||
fun dispose() { | ||
threadPool.shutdown() | ||
} | ||
} |
Oops, something went wrong.