summaryrefslogtreecommitdiff
path: root/odcsim-core/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2019-05-13 20:45:49 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2019-05-14 12:55:57 +0200
commit720d1f433e0fed0ee48cbebdb8f995e5d5fc7405 (patch)
tree21c5828f6dd6e0551e2675ef6fa73118818b797a /odcsim-core/src/main
parent03acc77d4f2841ea66a9200ab170e33a2d0518aa (diff)
bug: Replace initial behavior after starting coroutine
This change fixes the bug where suspending immediately after launching the coroutine, without replacing the current behavior causes a failure in the BehaviorInterpreter. This is because the initial behavior was not properly set.
Diffstat (limited to 'odcsim-core/src/main')
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt4
1 files changed, 3 insertions, 1 deletions
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt
index f9e8de00..82b29715 100644
--- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt
@@ -35,6 +35,7 @@ import com.atlarge.odcsim.Signal
import com.atlarge.odcsim.coroutines.SuspendingActorContext
import com.atlarge.odcsim.coroutines.SuspendingBehavior
import com.atlarge.odcsim.coroutines.suspendWithBehavior
+import com.atlarge.odcsim.empty
import com.atlarge.odcsim.receiveMessage
import com.atlarge.odcsim.receiveSignal
import org.slf4j.Logger
@@ -151,7 +152,8 @@ internal class SuspendingBehaviorImpl<T : Any>(
*/
internal fun start(): Behavior<T> {
val behavior = interpreter.behavior as SuspendingBehavior<T>
- val block: suspend () -> Behavior<T> = { behavior(this) }
+ val block = suspend { behavior(this) }
+ interpreter.become(actorContext, empty())
block.startCoroutine(SuspendingBehaviorImplContinuation())
return next
}