Struct holochain_websocket::ListenerHandle[][src]

pub struct ListenerHandle { /* fields omitted */ }
Expand description

Handle for shutting down a listener stream.

Example

use futures::stream::StreamExt;
use holochain_websocket::*;
use url2::url2;

#[tokio::main]
async fn main() {
    let (listener_handle, mut listener_stream) = WebsocketListener::bind_with_handle(
        url2!("ws://127.0.0.1:12345"),
        std::sync::Arc::new(WebsocketConfig::default()),
    )
    .await
    .unwrap();

    tokio::spawn(async move { while let Some(Ok(_)) = listener_stream.next().await {} });
    listener_handle.close();
}

Implementations

Shutdown the listener stream.

Get the url of the bound local listening socket.

Get the config associated with this listener.

Close the listener when the future resolves to true. If the future returns false the listener will not be closed.

 tokio::spawn(async move { while let Some(Ok(_)) = listener_stream.next().await {} });
 let (tx, rx) = tokio::sync::oneshot::channel();
 tokio::task::spawn(listener_handle.close_on(async move { rx.await.unwrap_or(true) }));
 tx.send(true).unwrap();

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.