Struct async_cpupool::CpuPool
source · pub struct CpuPool { /* private fields */ }
Expand description
The CPUPool handle
Implementations§
source§impl CpuPool
impl CpuPool
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new CpuPool with the default configuration
Example:
let pool = CpuPool::new();
sourcepub fn configure() -> Config
pub fn configure() -> Config
Create a configuration builder to customize the CpuPool
Example:
let pool = CpuPool::configure().build()?;
sourcepub fn spawn<F, T>(
&self,
send_fn: F
) -> impl Future<Output = Result<T, Canceled>> + '_
pub fn spawn<F, T>( &self, send_fn: F ) -> impl Future<Output = Result<T, Canceled>> + '_
Spawn a blocking operation on the CpuPool
Example:
let pool = CpuPool::new();
pool.spawn(|| std::thread::sleep(std::time::Duration::from_secs(3))).await?;
sourcepub async fn close(self) -> bool
pub async fn close(self) -> bool
Attempt to close the CpuPool
This operation returns true
when the pool was succesfully closed, or false
if there
exist other references to the pool, preventing closure.
It is not required to call close to close a CpuPool. CpuPools will automatically close themselves when all clones are dropped. This is simply a method to integrate better with async runtimes. Example:
let pool = CpuPool::new();
let closed = pool.close().await;
assert!(closed);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CpuPool
impl RefUnwindSafe for CpuPool
impl Send for CpuPool
impl Sync for CpuPool
impl Unpin for CpuPool
impl UnwindSafe for CpuPool
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more