diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-12-31 15:29:46 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-12-31 15:29:46 +0100 |
| commit | 3054f3a78ec467b032f2309222a3658ed3246977 (patch) | |
| tree | e3165ce49d874d636d0f10c52ec324337650125f /simulator/opendc-simulator | |
| parent | 4eabdea0eeceac91debf896cc8d7e0ef9d3e9c82 (diff) | |
Update to kotlinx-coroutines 1.4.2
Diffstat (limited to 'simulator/opendc-simulator')
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt index c6d5bdd1..4340708f 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt @@ -95,6 +95,8 @@ public class SimBareMetalMachine( return object : SelectClause0 { @InternalCoroutinesApi override fun <R> registerSelectClause0(select: SelectInstance<R>, block: suspend () -> R) { + val context = select.completion.context + // Do not reset the usage state: we will set it ourselves usageFlush?.dispose() usageFlush = null @@ -139,7 +141,7 @@ public class SimBareMetalMachine( } // Schedule the flush after the entire slice has finished - currentDisposable = delay.invokeOnTimeout(duration, action) + currentDisposable = delay.invokeOnTimeout(duration, action, context) // Start the slice work currentWork = work @@ -158,11 +160,13 @@ public class SimBareMetalMachine( currentWork?.stop(duration) currentDisposable?.dispose() - // Schedule reset the usage of the machine since the call is returning - usageFlush = delay.invokeOnTimeout(1) { + val action = { usageState.value = 0.0 usageFlush = null } + + // Schedule reset the usage of the machine since the call is returning + usageFlush = delay.invokeOnTimeout(1, action, context) } select.disposeOnSelect(disposable) |
