Struct PollSemaphore

struct PollSemaphore { ... }

A wrapper around Semaphore that provides a poll_acquire method.

Implementations

impl PollSemaphore

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

Create a new PollSemaphore.

fn close(self: &Self)

Closes the semaphore.

fn clone_inner(self: &Self) -> Arc<Semaphore>

Obtain a clone of the inner semaphore.

fn into_inner(self: Self) -> Arc<Semaphore>

Get back the inner semaphore.

fn poll_acquire(self: &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.

fn poll_acquire_many(self: &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.

fn available_permits(self: &Self) -> usize

Returns the current number of available permits.

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

fn add_permits(self: &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.

impl AsRef for PollSemaphore

fn as_ref(self: &Self) -> &Semaphore

impl Clone for PollSemaphore

fn clone(self: &Self) -> PollSemaphore

impl Debug for PollSemaphore

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

impl Freeze for PollSemaphore

impl RefUnwindSafe for PollSemaphore

impl Send for PollSemaphore

impl Stream for PollSemaphore

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

impl Sync for PollSemaphore

impl Unpin for PollSemaphore

impl UnsafeUnpin for PollSemaphore

impl UnwindSafe for PollSemaphore

impl<T> Any for PollSemaphore

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for PollSemaphore

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for PollSemaphore

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

impl<T> CloneToUninit for PollSemaphore

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

impl<T> From for PollSemaphore

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for PollSemaphore

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for PollSemaphore

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for PollSemaphore

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

impl<T, U> TryInto for PollSemaphore

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