it.unibo.jakta.agents.fsm.impl.SyncRunner.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jakta-state-machine Show documentation
Show all versions of jakta-state-machine Show documentation
A Kotlin internal DSL for the definition of BDI agents
package it.unibo.jakta.agents.fsm.impl
import it.unibo.jakta.agents.fsm.Activity
import it.unibo.jakta.agents.fsm.time.Time
import it.unibo.jakta.agents.utils.Promise
/**
* [AbstractRunner] implementation that executes the FSM on the current thread.
*/
class SyncRunner(override val activity: Activity) : AbstractRunner(activity) {
override fun onPause() = error("Is not possible to PAUSE a SyncRunner")
override fun onResume() = error("Is not possible to RESUME a SyncRunner")
override fun getCurrentTime(): Time = Time.real(System.currentTimeMillis())
override fun run(): Promise {
val promise = Promise()
while (!isOver) {
safeExecute({ promise.completeExceptionally(it) }) {
doStateTransition()
}
}
promise.complete(null)
return promise
}
}