V0.6.1 Arroyo Toad

This commit is contained in:
Christian Risi
2024-12-03 21:52:02 +00:00
parent 5d5cc7ef0a
commit 0c294045dc
2 changed files with 77 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ public actor IoTSimulatorCore {
// schedule work
let task = IoTSimulatorCore.schedule(envID: environment.location, deviceID: device.deviceID) { msg in
print("\(msg.description)\n\n")
//print("\(msg.description)\n\n")
} failure: {
print("Something is wrong")
}
@@ -47,6 +47,12 @@ public actor IoTSimulatorCore {
return IoTSimulatorCore.devices[devID]
}
public static func nukeAll() {
for value in IoTSimulatorCore.dev_tasks {
value.value.cancel()
}
}
private static func schedule(
envID: sending String,
deviceID: sending String,
@@ -55,9 +61,13 @@ public actor IoTSimulatorCore {
) -> Task<(), Never> {
return Task {
while true {
let dev = IoTSimulatorCore.getDev(devID: deviceID)!
let env = IoTSimulatorCore.getEnv(name: envID)!
var notCancelled: Bool = true
let dev = IoTSimulatorCore.getDev(devID: deviceID)!
let env = IoTSimulatorCore.getEnv(name: envID)!
while notCancelled {
usleep(__useconds_t(dev.dutyCicle * 1000))
let message = dev.work(envrionment: env)
do {
@@ -65,8 +75,18 @@ public actor IoTSimulatorCore {
} catch {
failure()
}
usleep(__useconds_t(dev.dutyCicle * 1000))
do {
try Task.checkCancellation()
} catch {
notCancelled = false
}
}
print("Bye, Bye, \(dev.deviceID)\n\n")
}
}