forked from NationTech/harmony
refact: Discovery callback takes a closure and fix git dependency hash
This commit is contained in:
@@ -4,7 +4,8 @@ use crate::local_presence::SERVICE_NAME;
|
||||
|
||||
pub type DiscoveryEvent = ServiceEvent;
|
||||
|
||||
pub fn discover_agents(timeout: Option<u64>, on_event: fn(&DiscoveryEvent)) {
|
||||
pub fn discover_agents(timeout: Option<u64>, on_event: impl Fn(DiscoveryEvent) + Send + 'static)
|
||||
{
|
||||
// Create a new mDNS daemon.
|
||||
let mdns = ServiceDaemon::new().expect("Failed to create mDNS daemon");
|
||||
|
||||
@@ -14,7 +15,7 @@ pub fn discover_agents(timeout: Option<u64>, on_event: fn(&DiscoveryEvent)) {
|
||||
|
||||
std::thread::spawn(move || {
|
||||
while let Ok(event) = receiver.recv() {
|
||||
on_event(&event);
|
||||
on_event(event.clone());
|
||||
match event {
|
||||
ServiceEvent::ServiceResolved(resolved) => {
|
||||
println!("Resolved a new service: {}", resolved.fullname);
|
||||
|
||||
Reference in New Issue
Block a user