From f4d2280680c4704839d2fc7a5d0d6edb5181f8a7 Mon Sep 17 00:00:00 2001 From: Jared Burce Date: Thu, 29 Oct 2020 06:06:48 -0700 Subject: [PATCH] Factor warp config into separate function --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 318a059..0d10408 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,10 @@ use warp::{Filter, sse, sse::ServerSentEvent}; const OUTDOOR_CHIME_FILE: &str = "static/outdoor.mp3"; const BUTTON_PIN: u8 = 26; +const CHANNEL_VEC_SIZE: usize = 32; -fn button_pressed(_level: Level, clients: &Arc; 8]>>>) { +fn button_pressed(_level: Level, + clients: &Arc; CHANNEL_VEC_SIZE]>>>) { info!("DOORBELL PRESS"); clients.lock().unwrap().retain(|tx: &mut mpsc::Sender<()>| { match tx.try_send(()) { @@ -44,6 +46,11 @@ async fn main() { pin.set_async_interrupt(Trigger::FallingEdge, move |level| button_pressed(level, &clients)) .expect("set interrupt"); + let warp = warp(events_clients); + warp.await; +} + +async fn warp(clients: Arc; CHANNEL_VEC_SIZE]>>>) { // GET / let root = warp::path::end() .and(warp::get()) @@ -56,7 +63,7 @@ async fn main() { .map(move || { info!("GET /events"); let (tx, rx) = mpsc::channel(1); - events_clients.lock().unwrap().push(tx); + clients.lock().unwrap().push(tx); let stream = stream::select( interval(Duration::from_secs(3)).map(move |_| {