File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
commonMain/kotlin/space/kscience/controls/constructor/models/continuous
commonTest/kotlin/space/kscience/controls/constructor Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ package space.kscience.controls.constructor.models.continuous
2+
3+ import kotlinx.coroutines.CoroutineScope
4+ import kotlinx.coroutines.delay
5+ import space.kscience.controls.constructor.DeviceState
6+ import space.kscience.controls.constructor.LateBindDeviceState
7+ import space.kscience.controls.constructor.transform
8+ import space.kscience.controls.constructor.units.Amount
9+ import space.kscience.controls.constructor.units.Numeric
10+ import space.kscience.controls.constructor.units.UnitsOfMeasurement
11+ import kotlin.time.Duration
12+
13+
14+ public fun <U : UnitsOfMeasurement , T : Amount <U >> ContinuousProducerInterface <U , T >.delayedProduction (
15+ scope : CoroutineScope ,
16+ delay : Duration
17+ ): ContinuousProducerInterface <U , T > = object : ContinuousProducerInterface <U , T > {
18+
19+ override val production: DeviceState <T > = DeviceState .transform(
20+ state = this @delayedProduction.production,
21+ scope = scope,
22+ initialValue = this @delayedProduction.production.value
23+ ) {
24+ delay(delay)
25+ it
26+ }
27+
28+
29+ override val productionCapacity: DeviceState <T > get() = this @delayedProduction.productionCapacity
30+
31+ override val consumerRequest: LateBindDeviceState <Numeric <U >> get() = this @delayedProduction.consumerRequest
32+ }
Original file line number Diff line number Diff line change @@ -220,6 +220,7 @@ class ContinuousFlowTest {
220220 transformer.connectProducer(producer)
221221 transformer.connectConsumer(consumer)
222222 }
223+
223224 }.runSimulation {
224225 assertEquals(0.1 , transformer.production.value.value)
225226 assertEquals(0.1 , consumer.consumation.value.value)
You can’t perform that action at this time.
0 commit comments