Refactor asynchronous actions to avoid thread usage

Adds custom coroutines specifically for use within Actions.  This
implements all features of the previous system, however, does not rely
on a separate executor to wake up continuations.

Note: since Actions are still ran by an executor and a small chance of
overlap exists the ActionCoroutine implementation uses atomic counters
and references.
This commit is contained in:
Gary Tierney
2017-09-19 01:52:10 +01:00
parent 169d89ffc0
commit 76dd8ba192
9 changed files with 220 additions and 122 deletions
@@ -0,0 +1,39 @@
package org.apollo.game.action
import org.apollo.game.action.ActionCoroutine
import org.junit.Assert.*
import org.junit.Test
class ActionCoroutineTest {
@Test
fun `Coroutine execution resumes after a pulse() call`() {
val coroutine = ActionCoroutine.start {
wait(1)
}
coroutine.pulse()
assertTrue(coroutine.stopped())
}
@Test
fun `Coroutine suspends on wait() calls`() {
val coroutine = ActionCoroutine.start {
wait(1)
}
// Check that the continuation is still waiting on a pulse.
assertFalse(coroutine.stopped())
}
@Test
fun `Coroutine cancels on stop() calls`() {
val coroutine = ActionCoroutine.start {
stop()
wait(1)
}
assertTrue(coroutine.stopped())
coroutine.pulse()
assertTrue(coroutine.stopped())
}
}