Struct holochain_websocket::ListenerHandle
source · [−]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
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
impl !RefUnwindSafe for ListenerHandle
impl Send for ListenerHandle
impl Sync for ListenerHandle
impl Unpin for ListenerHandle
impl !UnwindSafe for ListenerHandle
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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