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

commonMain.it.unibo.pulvreakt.runtime.PulvreaktRuntime.kt Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
package it.unibo.pulvreakt.runtime

import arrow.core.Either
import arrow.core.raise.either
import it.unibo.pulvreakt.api.infrastructure.Host
import it.unibo.pulvreakt.api.initializable.ManagedResource
import it.unibo.pulvreakt.dsl.model.PulvreaktConfiguration
import it.unibo.pulvreakt.runtime.errors.RuntimeError

/**
 * The [PulvreaktRuntime] is the main entry point of the runtime.
 */
interface PulvreaktRuntime : ManagedResource {
    /**
     * Starts the runtime.
     */
    suspend fun start(): Either

    /**
     * Stops the runtime.
     */
    suspend fun stop(): Either

    companion object {
        /**
         * Smart constructor for [PulvreaktRuntime].
         * @return an [Either] with [RuntimeError] on the left side and [PulvreaktRuntime] on the right side.
         */
        suspend operator fun invoke(
            config: PulvreaktConfiguration,
            device: String,
            id: Int,
            host: Host,
        ): Either = either {
            val runtime = PulvreaktRuntimeImpl(config, device, id, host)
            runtime.initialize().bind()
            runtime
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy