Sending the end file event out to listeners.

This commit is contained in:
Tom Alexander 2022-02-21 18:30:03 -05:00
parent 0dd5cf8fe4
commit 860f5759c1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -88,8 +88,8 @@ impl MpvCtl {
db: &CommandDb, db: &CommandDb,
event_listeners: &EventDb, event_listeners: &EventDb,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
match framed_read.read_frame().await { let current_frame = framed_read.read_frame().await.map_err(|e| e.to_string())?;
Ok(Some(frame)) => { if let Some(frame) = current_frame {
println!("Read {}", frame); println!("Read {}", frame);
// check if its an event // check if its an event
let is_event = match &frame { let is_event = match &frame {
@ -104,7 +104,7 @@ impl MpvCtl {
} }
}; };
match obj.get("event") { match obj.get("event") {
Some(orig @ serde_json::Value::String(s)) => { Some(serde_json::Value::String(s)) => {
println!("Notifying listeners for event {}", s); println!("Notifying listeners for event {}", s);
let listeners = { let listeners = {
let db_handle = event_listeners.lock().unwrap(); let db_handle = event_listeners.lock().unwrap();
@ -114,7 +114,7 @@ impl MpvCtl {
} }
}; };
for listener in listeners { for listener in listeners {
listener.send(frame.clone()).await; listener.send(frame.clone()).await?;
} }
} }
_ => return Err("Event with no string value".into()), _ => return Err("Event with no string value".into()),
@ -149,14 +149,9 @@ impl MpvCtl {
return Err("No entry found for request id".into()); return Err("No entry found for request id".into());
} }
} }
} } else if let None = current_frame {
Ok(None) => {
return Ok(()); return Ok(());
} };
Err(e) => {
return Err("Ran into a problem".into());
}
}
Ok(()) Ok(())
} }