summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-core/src/main/kotlin
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-03-05 13:23:57 +0100
committerGitHub <noreply@github.com>2024-03-05 13:23:57 +0100
commit5864cbcbfe2eb8c36ca05c3a39c7e5916aeecaec (patch)
tree5b2773b8dc21c2e1b526fb70f829c376dd80532a /opendc-simulator/opendc-simulator-core/src/main/kotlin
parentd28002a3c151d198298574312f32f1cb43f3a660 (diff)
Updated package versions, updated web server tests. (#207)
* Updated all package versions including kotlin. Updated all web-server tests to run. * Changed the java version of the tests. OpenDC now only supports java 19. * small update * test update * new update * updated docker version to 19 * updated docker version to 19
Diffstat (limited to 'opendc-simulator/opendc-simulator-core/src/main/kotlin')
-rw-r--r--opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt16
-rw-r--r--opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt2
2 files changed, 10 insertions, 8 deletions
diff --git a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt
index 271b89e0..bc232ce0 100644
--- a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt
+++ b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt
@@ -66,14 +66,15 @@ import kotlin.coroutines.EmptyCoroutineContext
public fun runSimulation(
context: CoroutineContext = EmptyCoroutineContext,
scheduler: SimulationDispatcher = SimulationDispatcher(),
- body: suspend SimulationCoroutineScope.() -> Unit
+ body: suspend SimulationCoroutineScope.() -> Unit,
) {
val (safeContext, job, dispatcher) = context.checkArguments(scheduler)
val startingJobs = job.activeJobs()
val scope = SimulationCoroutineScope(safeContext)
- val deferred = scope.async {
- body(scope)
- }
+ val deferred =
+ scope.async {
+ body(scope)
+ }
dispatcher.advanceUntilIdle()
deferred.getCompletionExceptionOrNull()?.let {
throw it
@@ -105,9 +106,10 @@ private fun Job.activeJobs(): Set<Job> {
* Convert a [ContinuationInterceptor] into a [SimulationDispatcher] if possible.
*/
internal fun ContinuationInterceptor.asSimulationDispatcher(): SimulationDispatcher {
- val provider = this as? DispatcherProvider ?: throw IllegalArgumentException(
- "DispatcherProvider such as SimulatorCoroutineDispatcher as the ContinuationInterceptor(Dispatcher) is required"
- )
+ val provider =
+ this as? DispatcherProvider ?: throw IllegalArgumentException(
+ "DispatcherProvider such as SimulatorCoroutineDispatcher as the ContinuationInterceptor(Dispatcher) is required",
+ )
return provider.dispatcher as? SimulationDispatcher ?: throw IllegalArgumentException("Active dispatcher is not a SimulationDispatcher")
}
diff --git a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt
index ca49fc53..a29e9404 100644
--- a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt
+++ b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt
@@ -43,7 +43,7 @@ public interface SimulationCoroutineScope : CoroutineScope, SimulationController
*/
public fun SimulationCoroutineScope(
context: CoroutineContext = EmptyCoroutineContext,
- scheduler: SimulationDispatcher = SimulationDispatcher()
+ scheduler: SimulationDispatcher = SimulationDispatcher(),
): SimulationCoroutineScope {
var safeContext = context
val simulationDispatcher: SimulationDispatcher