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
sourceimpl ListenerHandle
impl ListenerHandle
sourcepub fn local_addr(&self) -> &Url2
pub fn local_addr(&self) -> &Url2
Get the url of the bound local listening socket.
sourcepub fn get_config(&self) -> Arc<WebsocketConfig>
pub fn get_config(&self) -> Arc<WebsocketConfig>
Get the config associated with this listener.
sourcepub async fn close_on<F>(self, f: F) where
F: Future<Output = bool>,
pub async fn close_on<F>(self, f: F) where
F: Future<Output = bool>,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more