mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 08:40:08 +00:00
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:
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user