diff --git a/src/dealer.rs b/src/dealer.rs index 04cfe74..e468127 100644 --- a/src/dealer.rs +++ b/src/dealer.rs @@ -31,7 +31,7 @@ impl Drop for DealerSocket { #[async_trait] impl Socket for DealerSocket { fn with_options(options: SocketOptions) -> Self { - let fair_queue = FairQueue::new(true); + let fair_queue = FairQueue::new(options.block_on_no_clients); Self { backend: Arc::new(GenericSocketBackend::with_options( Some(fair_queue.inner()), diff --git a/src/lib.rs b/src/lib.rs index e244d5f..c7f543a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,9 +169,19 @@ pub enum SocketEvent { Disconnected(PeerIdentity), } -#[derive(Default)] +#[derive(Debug, Clone)] pub struct SocketOptions { pub(crate) peer_id: Option, + pub(crate) block_on_no_clients: bool, +} + +impl Default for SocketOptions { + fn default() -> Self { + Self { + peer_id: Default::default(), + block_on_no_clients: true, + } + } } impl SocketOptions { @@ -179,6 +189,10 @@ impl SocketOptions { self.peer_id = Some(peer_id); self } + pub fn block_on_no_clients(&mut self, block_on_no_clients: bool) -> &mut Self { + self.block_on_no_clients = block_on_no_clients; + self + } } #[async_trait] diff --git a/src/pull.rs b/src/pull.rs index 0144869..ae2577d 100644 --- a/src/pull.rs +++ b/src/pull.rs @@ -25,7 +25,7 @@ pub struct PullSocket { #[async_trait] impl Socket for PullSocket { fn with_options(options: SocketOptions) -> Self { - let fair_queue = FairQueue::new(true); + let fair_queue = FairQueue::new(options.block_on_no_clients); Self { backend: Arc::new(GenericSocketBackend::with_options( Some(fair_queue.inner()), diff --git a/src/rep.rs b/src/rep.rs index 2243f69..9a927a6 100644 --- a/src/rep.rs +++ b/src/rep.rs @@ -43,7 +43,7 @@ impl Drop for RepSocket { #[async_trait] impl Socket for RepSocket { fn with_options(options: SocketOptions) -> Self { - let fair_queue = FairQueue::new(true); + let fair_queue = FairQueue::new(options.block_on_no_clients); Self { backend: Arc::new(RepSocketBackend { peers: DashMap::new(), diff --git a/src/router.rs b/src/router.rs index 4ffb4b0..159c226 100644 --- a/src/router.rs +++ b/src/router.rs @@ -32,7 +32,7 @@ impl Drop for RouterSocket { #[async_trait] impl Socket for RouterSocket { fn with_options(options: SocketOptions) -> Self { - let fair_queue = FairQueue::new(true); + let fair_queue = FairQueue::new(options.block_on_no_clients); Self { backend: Arc::new(GenericSocketBackend::with_options( Some(fair_queue.inner()), diff --git a/src/sub.rs b/src/sub.rs index 9e4818b..5813b39 100644 --- a/src/sub.rs +++ b/src/sub.rs @@ -156,7 +156,7 @@ impl SubSocket { #[async_trait] impl Socket for SubSocket { fn with_options(options: SocketOptions) -> Self { - let fair_queue = FairQueue::new(true); + let fair_queue = FairQueue::new(options.block_on_no_clients); Self { backend: Arc::new(SubSocketBackend::with_options( Some(fair_queue.inner()),