create an mqtt_dummy that sends string every second
All checks were successful
Unit Tests / Run Tests (push) Successful in 14s
All checks were successful
Unit Tests / Run Tests (push) Successful in 14s
This commit is contained in:
parent
ed37e1c550
commit
af4f5a850c
6 changed files with 133 additions and 4 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import config
|
||||
import gleam/erlang/process
|
||||
import gleam/io
|
||||
import mqtt_dummy
|
||||
|
||||
pub fn main() -> Nil {
|
||||
case config.load_config() {
|
||||
|
|
@ -14,4 +16,40 @@ pub fn main() -> Nil {
|
|||
io.println("Failed to load config: " <> err)
|
||||
}
|
||||
}
|
||||
|
||||
let assert Ok(subject) = mqtt_dummy.start()
|
||||
let mailbox = mqtt_dummy.subscribe(subject)
|
||||
|
||||
// Kick off the first message
|
||||
process.send_after(subject, 1000, mqtt_dummy.Proc)
|
||||
|
||||
receive_and_reschedule(mailbox, subject)
|
||||
// case process.receive(mailbox, 5000) {
|
||||
// Ok(msg) -> {
|
||||
// io.println("Got message:" <> msg)
|
||||
// // process_messages(mailbox, n - 1)
|
||||
// }
|
||||
// Error(Nil) -> {
|
||||
// io.println("Timeout waiting for message")
|
||||
// }
|
||||
// }
|
||||
Nil
|
||||
}
|
||||
|
||||
fn receive_and_reschedule(
|
||||
mailbox: process.Subject(String),
|
||||
subject: process.Subject(mqtt_dummy.Message),
|
||||
) -> Nil {
|
||||
case process.receive(mailbox, 2000) {
|
||||
Ok(msg) -> {
|
||||
io.println("Got message: " <> msg)
|
||||
// Reschedule the next Proc message
|
||||
process.send_after(subject, 1000, mqtt_dummy.Proc)
|
||||
receive_and_reschedule(mailbox, subject)
|
||||
}
|
||||
Error(Nil) -> {
|
||||
io.println("Timeout - waiting again...")
|
||||
receive_and_reschedule(mailbox, subject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue