nukkeldev / mdns-impl

An exploration of MDNS/DNS-SD.
MIT License
1 stars 0 forks source link

`BrowsingContext`: An asynchronous, pollable service discovery struct #3

Open nukkeldev opened 7 months ago

nukkeldev commented 7 months ago

BrowsingContext allows for the user to declare a single, or multiple, type(s) of services they are interested in and poll the instance to get discovered Services.

Usage of this might look something like:

let ctx: BrowsingContext = BrowsingContext::new().query("_http._tcp.local").query("_http-alt._tcp.local").search();
let mut services = vec![];

loop {
    if let Some(service) = ctx.poll() {
        services.push(service);
    }

    // ...
}

I take inspiration to other APIs that do similar things, such as sockets, IO, etc., and have a sort of queue-based polling system which I think works well for now. If not, I can change it at a later date, but it will suffice for an initial implementation.

nukkeldev commented 7 months ago

Actually, on second thought, polling would be unfit for the sorts of applications I want to use this for, those being non-immediate mode UI. Rather an Arc<Mutex<Vec<Service>>> might be better.