tokio_util::sync

Struct PollSemaphore

Source
pub struct PollSemaphore { /* private fields */ }
Expand description

A wrapper around Semaphore that provides a poll_acquire method.

Implementations§

Source§

impl PollSemaphore

Source

pub fn new(semaphore: Arc<Semaphore>) -> Self

Create a new PollSemaphore.

Source

pub fn close(&self)

Closes the semaphore.

Source

pub fn clone_inner(&self) -> Arc<Semaphore>

Obtain a clone of the inner semaphore.

Source

pub fn into_inner(self) -> Arc<Semaphore>

Get back the inner semaphore.

Source

pub fn poll_acquire( &mut self, cx: &mut Context<'_>, ) -> Poll<Option<OwnedSemaphorePermit>>

Poll to acquire a permit from the semaphore.

This can return the following values:

  • Poll::Pending if a permit is not currently available.
  • Poll::Ready(Some(permit)) if a permit was acquired.
  • Poll::Ready(None) if the semaphore has been closed.

When this method returns Poll::Pending, the current task is scheduled to receive a wakeup when a permit becomes available, or when the semaphore is closed. Note that on multiple calls to poll_acquire, only the Waker from the Context passed to the most recent call is scheduled to receive a wakeup.

Source

pub fn poll_acquire_many( &mut self, cx: &mut Context<'_>, permits: u32, ) -> Poll<Option<OwnedSemaphorePermit>>

Poll to acquire many permits from the semaphore.

This can return the following values:

  • Poll::Pending if a permit is not currently available.
  • Poll::Ready(Some(permit)) if a permit was acquired.
  • Poll::Ready(None) if the semaphore has been closed.

When this method returns Poll::Pending, the current task is scheduled to receive a wakeup when the permits become available, or when the semaphore is closed. Note that on multiple calls to poll_acquire, only the Waker from the Context passed to the most recent call is scheduled to receive a wakeup.

Source

pub fn available_permits(&self) -> usize

Returns the current number of available permits.

This is equivalent to the Semaphore::available_permits method on the tokio::sync::Semaphore type.

Source

pub fn add_permits(&self, n: usize)

Adds n new permits to the semaphore.

The maximum number of permits is Semaphore::MAX_PERMITS, and this function will panic if the limit is exceeded.

This is equivalent to the Semaphore::add_permits method on the tokio::sync::Semaphore type.

Trait Implementations§

Source§

impl AsRef<Semaphore> for PollSemaphore

Source§

fn as_ref(&self) -> &Semaphore

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for PollSemaphore

Source§

fn clone(&self) -> PollSemaphore

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PollSemaphore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Stream for PollSemaphore

Source§

type Item = OwnedSemaphorePermit

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<OwnedSemaphorePermit>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes