All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.jakta.agents.fsm.impl.SyncRunner.kt Maven / Gradle / Ivy

There is a newer version: 0.11.106
Show newest version
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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy