Factor warp config into separate function
This commit is contained in:
11
src/main.rs
11
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<Mutex<SmallVec<[mpsc::Sender<()>; 8]>>>) {
|
||||
fn button_pressed(_level: Level,
|
||||
clients: &Arc<Mutex<SmallVec<[mpsc::Sender<()>; 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<Mutex<SmallVec<[mpsc::Sender<()>; 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 |_| {
|
||||
|
||||
Reference in New Issue
Block a user