diff --git a/README.md b/README.md
index 59be7c2..41de711 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ More information here:
https://blog.jetbrains.com/kotlin/2016/07/first-glimpse-of-kotlin-1-1-coroutines-type-aliases-and-more/
https://blog.jetbrains.com/kotlin/2016/10/kotlin-1-1-m02-is-here/
https://blog.jetbrains.com/kotlin/2016/11/kotlin-1-1-m03-is-here/
-
+https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-1-m04-is-here/
# Skedule
A small coroutine library for the BukkitScheduler for Bukkit/Spigot plugin developers using Kotlin
@@ -125,7 +125,7 @@ scheduler.schedule(plugin, SynchronizationContext.ASYNC) { //ASYNC here specifie
okkero
- http://nexus.elyc.in/repository/maven-releases/
+ http://nexus.okkero.com/repository/maven-releases/
```
@@ -134,7 +134,7 @@ scheduler.schedule(plugin, SynchronizationContext.ASYNC) { //ASYNC here specifie
com.okkero.skedule
skedule
- 1.0.0
+ 1.1.0
compile
diff --git a/pom.xml b/pom.xml
index 207fedd..71b4244 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.okkero.skedule
skedule
- 1.0.0
+ 1.1.0
jar
Skedule
@@ -14,17 +14,17 @@
deployment-elycin
- http://d.elyc.in:8081/repository/maven-releases/
+ http://nexus.okkero.com/repository/maven-releases/
deployment-elycin
- http://d.elyc.in:8081/repository/maven-snapshots/
+ http://nexus.okkero.com/repository/maven-snapshots/
UTF-8
- 1.1-M01
+ 1.1-M04
4.12
0.9.9
diff --git a/src/main/kotlin/com/okkero/skedule/SchedulerCoroutine.kt b/src/main/kotlin/com/okkero/skedule/SchedulerCoroutine.kt
index 75cb6b0..0563276 100644
--- a/src/main/kotlin/com/okkero/skedule/SchedulerCoroutine.kt
+++ b/src/main/kotlin/com/okkero/skedule/SchedulerCoroutine.kt
@@ -5,6 +5,10 @@ import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import org.bukkit.scheduler.BukkitScheduler
import org.bukkit.scheduler.BukkitTask
+import kotlin.coroutines.Continuation
+import kotlin.coroutines.RestrictsSuspension
+import kotlin.coroutines.createCoroutine
+import kotlin.coroutines.suspendCoroutine
/**
* Schedule a coroutine with the Bukkit Scheduler.
@@ -17,9 +21,10 @@ import org.bukkit.scheduler.BukkitTask
* @see SynchronizationContext
*/
fun BukkitScheduler.schedule(plugin: Plugin, initialContext: SynchronizationContext = SYNC,
- coroutine co: BukkitSchedulerController.() -> Continuation): CoroutineTask {
+ co: suspend BukkitSchedulerController.() -> Unit): CoroutineTask {
val controller = BukkitSchedulerController(plugin, this)
- controller.start(initialContext, controller.co())
+ val coroutine = co.createCoroutine(controller, completion = controller)
+ controller.start(initialContext, coroutine)
return CoroutineTask(controller)
}
@@ -33,7 +38,8 @@ fun BukkitScheduler.schedule(plugin: Plugin, initialContext: SynchronizationCont
* @property isRepeating whether this coroutine is currently backed by a repeating task
*/
//TODO Verify if thread safe
-class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitScheduler) {
+@RestrictsSuspension
+class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitScheduler) : Continuation {
private var schedulerDelegate: TaskScheduler = NonRepeatingTaskScheduler(plugin, scheduler)
@@ -58,7 +64,7 @@ class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitSchedul
*
* @return the actual amount of ticks waited
*/
- suspend fun waitFor(ticks: Long, cont: Continuation) {
+ suspend fun waitFor(ticks: Long): Long = suspendCoroutine { cont ->
schedulerDelegate.doWait(ticks, cont::resume)
}
@@ -70,7 +76,7 @@ class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitSchedul
*
* @return the actual amount of ticks waited
*/
- suspend fun yield(cont: Continuation) {
+ suspend fun yield(): Long = suspendCoroutine { cont ->
schedulerDelegate.doYield(cont::resume)
}
@@ -81,7 +87,7 @@ class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitSchedul
* @param context the context to switch to
* @return `true` if a context switch was made, `false` otherwise
*/
- suspend fun switchContext(context: SynchronizationContext, cont: Continuation) {
+ suspend fun switchContext(context: SynchronizationContext): Boolean = suspendCoroutine { cont ->
schedulerDelegate.doContextSwitch(context, cont::resume)
}
@@ -91,7 +97,7 @@ class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitSchedul
*
* @param context the synchronization context of the new task
*/
- suspend fun newContext(context: SynchronizationContext, cont: Continuation) {
+ suspend fun newContext(context: SynchronizationContext): Unit = suspendCoroutine { cont ->
schedulerDelegate.forceNewContext(context, { cont.resume(Unit) })
}
@@ -102,18 +108,18 @@ class BukkitSchedulerController(val plugin: Plugin, val scheduler: BukkitSchedul
* things like countdowns and delays at fixed intervals, since [waitFor] will not result in a new task being
* spawned.
*/
- suspend fun repeating(resolution: Long, cont: Continuation) {
+ suspend fun repeating(resolution: Long): Long = suspendCoroutine { cont ->
schedulerDelegate = RepeatingTaskScheduler(resolution, plugin, scheduler)
schedulerDelegate.forceNewContext(currentContext()) { cont.resume(0) }
}
- operator fun handleResult(result: Unit, cont: Continuation) {
+ override fun resume(result: Unit) {
currentTask?.cancel()
}
- operator fun handleException(e: Throwable, cont: Continuation) {
+ override fun resumeWithException(exception: Throwable) {
currentTask?.cancel()
- throw e
+ throw exception
}
}