[go: up one dir, main page]

Pager

Struct Pager 

Source
pub struct Pager<'s, S: SyncResult> { /* private fields */ }
Expand description

Tasks holding a Pager can remotely acquire a desired resource.

Pager contains a wait queue entry which forms an intrusive linked list. It is important that the Pager is not moved while it is registered in a synchronization primitive, otherwise it may lead to undefined behavior, therefore Pager does not implement Unpin.

Implementations§

Source§

impl<'s, S: SyncResult> Pager<'s, S>

Source

pub fn is_registered(self: &mut Pin<&mut Pager<'s, S>>) -> bool

Returns true if the Pager is registered in a synchronization primitive.

§Examples
use std::pin::pin;

use saa::{Gate, Pager};
use saa::gate::State;

let gate = Gate::default();

let mut pinned_pager = pin!(Pager::default());
assert!(!pinned_pager.is_registered());

assert!(gate.register_pager(&mut pinned_pager, false));
assert!(pinned_pager.is_registered());

assert!(!gate.register_pager(&mut pinned_pager, false));
assert!(pinned_pager.is_registered());
Source

pub async fn poll_async(self: &mut Pin<&mut Pager<'s, S>>) -> S::Result

Waits for the desired resource to become available asynchronously.

§Examples
use std::pin::pin;

use saa::{Gate, Pager};
use saa::gate::State;

let gate = Gate::default();

let mut pinned_pager = pin!(Pager::default());

assert!(gate.register_pager(&mut pinned_pager, false));

assert_eq!(gate.open().1, 1);

async {
    assert_eq!(pinned_pager.poll_async().await, Ok(State::Open));
};
Source

pub fn poll_sync(self: &mut Pin<&mut Pager<'s, S>>) -> S::Result

Waits for the desired resource to become available synchronously.

§Examples
use std::pin::pin;

use saa::{Gate, Pager};
use saa::gate::State;

let gate = Gate::default();

let mut pinned_pager = pin!(Pager::default());

assert!(gate.register_pager(&mut pinned_pager, true));

assert_eq!(gate.open().1, 1);

assert_eq!(pinned_pager.poll_sync(), Ok(State::Open));
Source

pub fn try_poll(self: &mut Pin<&mut Pager<'s, S>>) -> S::Result

Tries to get the result.

§Examples
use std::pin::pin;

use saa::{Gate, Pager};
use saa::gate::{Error, State};

let gate = Gate::default();

let mut pinned_pager = pin!(Pager::default());

assert_eq!(pinned_pager.try_poll(), Err(Error::NotRegistered));

assert!(gate.register_pager(&mut pinned_pager, true));

assert_eq!(pinned_pager.try_poll(), Err(Error::NotReady));
assert_eq!(gate.open().1, 1);

assert_eq!(pinned_pager.try_poll(), Ok(State::Open));

Trait Implementations§

Source§

impl<'s, S: Debug + SyncResult> Debug for Pager<'s, S>

Source§

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

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

impl<'s, S: Default + SyncResult> Default for Pager<'s, S>

Source§

fn default() -> Pager<'s, S>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'s, S> !Freeze for Pager<'s, S>

§

impl<'s, S> !RefUnwindSafe for Pager<'s, S>

§

impl<'s, S> Send for Pager<'s, S>
where S: Sync,

§

impl<'s, S> !Sync for Pager<'s, S>

§

impl<'s, S> !Unpin for Pager<'s, S>

§

impl<'s, S> UnwindSafe for Pager<'s, S>
where S: RefUnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.