Skip to content

Commit 4e48f03

Browse files
authored
Merge pull request Shynixn#88 from Shynixn/development
Merge changes to Master --release
2 parents a442864 + fa13663 commit 4e48f03

File tree

19 files changed

+378
-181
lines changed

19 files changed

+378
-181
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tasks.register("printVersion") {
4343

4444
subprojects {
4545
group 'com.github.shynixn.mccoroutine'
46-
version '2.7.0'
46+
version '2.8.0'
4747

4848
sourceCompatibility = 1.8
4949

docs/wiki/docs/bridge.md

Lines changed: 0 additions & 147 deletions
This file was deleted.

docs/wiki/docs/coroutine.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ how this can be translated to the world of minecraft plugins. It is recommended
99
### Starting a coroutine
1010

1111
For beginners, it is often confusing how to enter a coroutine. The examples in the official guide mostly use ``runBlocking``
12-
because it makes sense for testing. However, keep in mind to **never** use ``runblocking`` in any of your plugins.
12+
because it makes sense for testing. However, keep in mind to **avoid** using ``runblocking`` in any of your plugins.
1313

1414
* To enter a coroutine **anywhere** in your code at any time:
1515

@@ -29,9 +29,11 @@ A dispatcher determines what thread or threads the corresponding coroutine uses
2929
* minecraftDispatcher (Allows to execute coroutines on the main minecraft thread)
3030
* asyncDispatcher (Allows to execute coroutines on the async minecraft threadpool)
3131

32-
However, it is recommend to use ``Dispatchers.IO`` instead of asyncDispatcher because it is more optimized.
32+
!!! note "Important"
33+
**However, it is highly recommend to use ``Dispatchers.IO`` instead of asyncDispatcher because the scheduling is more accurate.**
34+
Additional technical details can be found here: [GitHub Issue](https://github.com/Shynixn/MCCoroutine/issues/87).
3335

34-
* An example how this works is shown below:
36+
An example how this works is shown below:
3537

3638
```kotlin
3739
fun foo() {
@@ -45,7 +47,8 @@ fun foo() {
4547

4648
// Here we are automatically back on the main thread again.
4749

48-
val result2 = withContext(plugin.asyncDispatcher) {
50+
// Prefer using Dispatchers.IO instead of asyncDispatcher
51+
val result2 = withContext(Dispatchers.IO) {
4952
// Perform operations asynchronously.
5053
" Max"
5154
}
@@ -60,7 +63,6 @@ fun foo() {
6063
Normally, you do not need to call ``plugin.minecraftDispatcher`` in your code. Instead, you are guaranteed to be always on the minecraft main thread
6164
in the ``plugin.launch{}`` scope and use sub coroutines (e.g. withContext) to perform asynchronous operations. Such a case can be found below:
6265

63-
6466
```kotlin
6567
@EventHandler
6668
fun onPlayerJoinEvent(event: PlayerJoinEvent) {
@@ -69,7 +71,7 @@ fun onPlayerJoinEvent(event: PlayerJoinEvent) {
6971
val name = event.player.name
7072
val listOfFriends = withContext(Dispatchers.IO) {
7173
// IO Thread
72-
val friendNames = Files.readAllLines(Paths.get("$name.json"))
74+
val friendNames = Files.readAllLines(Paths.get("$name.txt"))
7375
friendNames
7476
}
7577

@@ -81,6 +83,42 @@ fun onPlayerJoinEvent(event: PlayerJoinEvent) {
8183

8284
```
8385

86+
### Plugin launch Execution order
87+
88+
If you use ``plugin.launch``, it is important to understand the execution order.
89+
90+
````kotlin
91+
class Foo(private val plugin : Plugin) {
92+
93+
fun bar() {
94+
// Main Thread
95+
println("I am first")
96+
97+
val job = plugin.launch {
98+
println("I am second") // The context is not suspended when switching to the same suspendable context.
99+
delay(1000)
100+
println("I am fourth") // The context is given back after 1000 milliseconds and continuous here.
101+
bob()
102+
}
103+
104+
// When calling delay the suspendable context is suspended and the original context immediately continuous here.
105+
println("I am third")
106+
}
107+
108+
private suspend fun bob(){
109+
println("I am fifth")
110+
}
111+
}
112+
````
113+
114+
````kotlin
115+
"I am first"
116+
"I am second"
117+
"I am third"
118+
"I am fourth"
119+
"I am fifth"
120+
````
121+
84122
### Coroutines everywhere
85123

86124
Using ``plugin.launch{}``is valuable if you migrate existing plugins to use coroutines. However, if you write a new plugin from scratch, you may consider using

docs/wiki/docs/installation.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ In order to use the MCCoroutine Kotlin API, you need to include the following li
88

99
```groovy
1010
dependencies {
11-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.7.0")
12-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.7.0")
11+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.8.0")
12+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.8.0")
1313
}
1414
```
1515

1616
=== "BungeeCord"
1717

1818
```groovy
1919
dependencies {
20-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-api:2.7.0")
21-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-core:2.7.0")
20+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-api:2.8.0")
21+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-core:2.8.0")
2222
}
2323
```
2424

2525
=== "Sponge"
2626

2727
```groovy
2828
dependencies {
29-
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-api:2.7.0")
30-
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-core:2.7.0")
29+
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-api:2.8.0")
30+
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-core:2.8.0")
3131
}
3232
```
3333

3434
=== "Velocity"
3535

3636
```groovy
3737
dependencies {
38-
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-api:2.7.0")
39-
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-core:2.7.0")
38+
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-api:2.8.0")
39+
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-core:2.8.0")
4040
}
4141
```
4242

@@ -60,8 +60,8 @@ dependencies {
6060
**plugin.yml**
6161
```yaml
6262
libraries:
63-
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.7.0
64-
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.7.0
63+
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.8.0
64+
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.8.0
6565
```
6666

6767
=== "Other Server"

0 commit comments

Comments
 (0)