summaryrefslogtreecommitdiff
path: root/opendc-stdlib/src/main/kotlin
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-20 00:59:54 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-20 00:59:54 +0200
commit39cfa9724c71796f2c16aa1ed90fbd4425540eef (patch)
tree920ef35be300be4681ffd63f016f4db51ddd543e /opendc-stdlib/src/main/kotlin
parent90e0d1d8c6ab94e020dd4cb4831a369b270a69b7 (diff)
Add support for timeouts on receive calls
This change allows processes to set a timeout when waiting for a message to arrive.
Diffstat (limited to 'opendc-stdlib/src/main/kotlin')
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt4
1 files changed, 3 insertions, 1 deletions
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
index 0884a725..163f280f 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
@@ -28,6 +28,7 @@ import nl.atlarge.opendc.extension.destinations
import nl.atlarge.opendc.workload.Task
import nl.atlarge.opendc.kernel.Context
import nl.atlarge.opendc.kernel.Process
+import nl.atlarge.opendc.kernel.time.Duration
import nl.atlarge.opendc.topology.Entity
/**
@@ -60,6 +61,7 @@ class Machine : Entity<Machine.State>, Process<Machine> {
override suspend fun Context<Machine>.run() {
update(State(Status.IDLE))
+ val interval: Duration = 10
val cpus = outgoingEdges.destinations<Cpu>("cpu")
val speed = cpus.fold(0, { acc, (speed, cores) -> acc + speed * cores }).toLong()
var task: Task? = null
@@ -74,7 +76,7 @@ class Machine : Entity<Machine.State>, Process<Machine> {
}
}
- val msg = receive()
+ val msg = receive(interval)
if (msg is Task) {
task = msg
update(State(Status.RUNNING, task))