Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow overriding block_on_no_clients queue param #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,30 @@ pub enum SocketEvent {
Disconnected(PeerIdentity),
}

#[derive(Default)]
#[derive(Debug, Clone)]
pub struct SocketOptions {
pub(crate) peer_id: Option<PeerIdentity>,
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 {
pub fn peer_identity(&mut self, peer_id: PeerIdentity) -> &mut Self {
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]
Expand Down
2 changes: 1 addition & 1 deletion src/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion src/rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion src/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down