You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/wiki/docs/tasks.md
+16-6Lines changed: 16 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,7 @@ given time.
14
14
There is a big difference with ``delay()`` and ``Thread.sleep()``. Consult the official Kotlin Coroutines
15
15
documentation for details, however essentially ``Thread.sleep()`` blocks the thread for a given time and
16
16
``delay()`` suspends the thread for a given time. When a thread is suspended, it can do other work (e.g. server handles
17
-
other operations like players joining or commands) compared to when a thread is blocked, it cannot do other work (e.g. server appears frozen).
18
-
17
+
other operations like players joining or commands) compared to when a thread is blocked, it cannot do other work (e.g. server appears frozen).
19
18
20
19
````kotlin
21
20
suspendfunsayHello() {
@@ -29,23 +28,34 @@ If you are not in a ``suspend`` function, use ``plugin.launch`` together with ``
29
28
30
29
````kotlin
31
30
funsayHello() {
32
-
plugin.launch {
31
+
plugin.launch {
33
32
println("Please say hello in 2 seconds")
34
33
delay(2000) // Delay for 2000 milliseconds
35
34
println("hello")
36
-
}
35
+
}
37
36
}
38
37
````
39
38
39
+
## Delay Ticks
40
+
41
+
MCCoroutine offers an extension method to use delay together with Bukkit and Sponge ticks.
42
+
43
+
```kotlin
44
+
delay(1.ticks)
45
+
```
46
+
47
+
Prefer using ``delay(1.ticks)`` when delaying on the minecraft main thread instead of ``delay(50)``. The tick extension function is more accurate than using
48
+
milliseconds directly. The technical details are explained in this [github issue](https://github.com/Shynixn/MCCoroutine/issues/72).
49
+
40
50
## Repeating tasks
41
51
42
52
If you are already in a ``suspend`` function, you can simply use traditional loops with ``delay`` to repeat tasks.
43
53
44
54
````kotlin
45
55
suspendfunsayHello() {
46
56
println("Please say hello 10 times every 2 seconds")
0 commit comments