pub struct Sender { /* private fields */ }
Expand description
The sender part of the queue. This part is lock-free and therefore can be used outside an asynchronous context.
Implementations§
source§impl Sender
impl Sender
sourcepub fn open<P: AsRef<Path>>(base: P) -> Result<Sender>
pub fn open<P: AsRef<Path>>(base: P) -> Result<Sender>
Opens a queue on a folder indicated by the base
path for sending. The
folder will be created if it does not already exist.
Errors
This function will return an IO error if the queue is already in use for sending, which is indicated by a lock file. Also, any other IO error encountered while opening will be sent.
sourcepub fn save(&mut self) -> Result<()>
👎Deprecated since 0.5.0: the sender state is now always inferred. There is no need to save anything
pub fn save(&mut self) -> Result<()>
Saves the sender queue state. You do not need to use method in most circumstances, since it is automatically done on drop (yes, it will be called eve if your thread panics). However, you can use this function to
-
Make periodical backups. Use an external timer implementation for this.
-
Handle possible IO errors in sending. The
drop
implementation will ignore (but log) any io errors, which may lead to data loss in an unreliable filesystem. It was implemented this way because no errors are allowed to propagate on drop and panicking will abort the program if drop is called during a panic.
sourcepub fn try_send<D: AsRef<[u8]>>(
&mut self,
data: D
) -> Result<(), TrySendError<D>>
pub fn try_send<D: AsRef<[u8]>>( &mut self, data: D ) -> Result<(), TrySendError<D>>
Tries to sends some data into the queue. If the queue is too big to
insert (as set in max_queue_size
), this returns
TrySendError::QueueFull
. One send is always atomic.
Errors
This function returns any underlying errors encountered while writing or
flushing the queue. Also, it returns TrySendError::QueueFull
if the
queue is too big.
sourcepub async fn send<D: AsRef<[u8]>>(&mut self, data: D) -> Result<()>
pub async fn send<D: AsRef<[u8]>>(&mut self, data: D) -> Result<()>
Sends some data into the queue. One send is always atomic. This function is
async
because the queue might be full and so we need to .await
the
receiver to consume enough segments to clear the queue.
Errors
This function returns any underlying errors encountered while writing or flushing the queue.
sourcepub fn try_send_batch<I>(&mut self, it: I) -> Result<(), TrySendError<I>>where
I: IntoIterator,
I::Item: AsRef<[u8]>,
pub fn try_send_batch<I>(&mut self, it: I) -> Result<(), TrySendError<I>>where I: IntoIterator, I::Item: AsRef<[u8]>,
Tries to send all the contents of an iterable into the queue. If the
queue is too big to insert (as set in max_queue_size
), this returns
TrySendError::QueueFull
. All is buffered to be sent atomically, in
one flush operation. Since this operation is atomic, it does not create
new segments during the iteration. Be mindful of that when using this
method for large writes.
Errors
This function returns any underlying errors encountered while writing or
flushing the queue. Also, it returns TrySendError::QueueFull
if the
queue is too big.
sourcepub async fn send_batch<I>(&mut self, it: I) -> Result<()>where
I: IntoIterator,
I::Item: AsRef<[u8]>,
pub async fn send_batch<I>(&mut self, it: I) -> Result<()>where I: IntoIterator, I::Item: AsRef<[u8]>,
Sends all the contents of an iterable into the queue. This function is
async
because the queue might be full and so we need to .await
the
receiver to consume enough segments to clear the queue. All is buffered
to be sent atomically, in one flush operation. Since this operation is
atomic, it does not create new segments during the iteration. Be
mindful of that when using this method for large writes.
Errors
This function returns any underlying errors encountered while writing or flushing the queue.