From d40eae0264236be3a9d34f39a63adde8a9b47a57 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 14 Feb 2020 00:44:43 +0100 Subject: feat: Make ProcessContext a coroutine scope This change makes the ProcessContext implement the CoroutineScope in order to launch local coroutines bound to the lifecycle of the logical process. --- .../odcsim-api/src/main/kotlin/com/atlarge/odcsim/ProcessContext.kt | 3 ++- .../kotlin/com/atlarge/odcsim/engine/omega/OmegaSimulationEngine.kt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'odcsim') diff --git a/odcsim/odcsim-api/src/main/kotlin/com/atlarge/odcsim/ProcessContext.kt b/odcsim/odcsim-api/src/main/kotlin/com/atlarge/odcsim/ProcessContext.kt index 20d48ab3..30ef4114 100644 --- a/odcsim/odcsim-api/src/main/kotlin/com/atlarge/odcsim/ProcessContext.kt +++ b/odcsim/odcsim-api/src/main/kotlin/com/atlarge/odcsim/ProcessContext.kt @@ -27,12 +27,13 @@ package com.atlarge.odcsim import java.time.Clock import kotlin.coroutines.CoroutineContext import kotlin.coroutines.coroutineContext +import kotlinx.coroutines.CoroutineScope import org.slf4j.Logger /** * Represents the execution context of a logical process in simulation. */ -public interface ProcessContext : CoroutineContext.Element { +public interface ProcessContext : CoroutineContext.Element, CoroutineScope { /** * Key for [ProcessContext] instance in the coroutine context. */ diff --git a/odcsim/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaSimulationEngine.kt b/odcsim/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaSimulationEngine.kt index 7a147291..207d2768 100644 --- a/odcsim/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaSimulationEngine.kt +++ b/odcsim/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaSimulationEngine.kt @@ -232,6 +232,10 @@ class OmegaSimulationEngine(rootBehavior: Behavior, override val name: String) : override val key: CoroutineContext.Key<*> = ProcessContext.Key + @InternalCoroutinesApi + override val coroutineContext: CoroutineContext + get() = context + @InternalCoroutinesApi override val context: CoroutineContext = this + dispatcher + job } -- cgit v1.2.3