Struct PollSemaphore

pub struct PollSemaphore { /* private fields */ }

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)

Closes the semaphore.

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

Obtain a clone of the inner semaphore.

fn into_inner(self) -> Arc<Semaphore>

Get back the inner semaphore.

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.

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.

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.

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

impl AsRef<Semaphore> for PollSemaphore

fn as_ref(&self) -> &Semaphore

impl Clone for PollSemaphore

fn clone(&self) -> PollSemaphore

impl Debug for PollSemaphore

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

impl Stream for PollSemaphore

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

Auto Trait Implementations

impl !RefUnwindSafe for PollSemaphore

impl !UnwindSafe for PollSemaphore

impl Freeze for PollSemaphore

impl Send for PollSemaphore

impl Sync for PollSemaphore

impl Unpin for PollSemaphore

impl UnsafeUnpin for PollSemaphore

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for PollSemaphore

fn from(t: T) -> T

Returns the argument unchanged.

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(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<U> for PollSemaphore where U: Into<T>,

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

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

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