pub struct ListenerHandle { /* private fields */ }
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

Returns the argument unchanged.

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
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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more