Expand description
This crate provides:
-
A specialized, custom thread pool,
DispatchPool
, for offloading blocking or otherwise long running operations from a main or reactor thread(s). Once registered, it is used viadispatch_rx()
(to await a return value) ordispatch()
for background tasks (fire and forget). -
A
BlockingPermit
, obtained viablocking_permit_future()
for limiting the number of concurrent blocking operations via a re-exportedSemaphore
type selected by one of the (non-default) features futures-intrusive, or tokio-semaphore (or tokio-omnibus). -
A
Cleaver
for splittingStream
buffers into more manageable sizes. -
A
YieldStream
for yielding betweenStream
items.
§Optional Features
The following features may be enabled at build time. All are disabled by default, unless otherwise noted.
futures-channel : Use this oneshot channel implementation (Default enabled, but overridden by tokio-oneshot or tokio-omnibus.)
tokio-oneshot : Use tokio’s oneshot channel implementation (Overrides futures-channel default.).
futures-intrusive
: Include BlockingPermit
and re-export Semaphore
from the
futures-intrusive crate. (Works with all prominent runtimes.)
tokio-semaphore
: Include BlockingPermit
and re-export tokio’s Semaphore
type. (Overrides futures-intrusive.)
tokio-threaded
: Add block_in_place
support, exposed via BlockingPermit::run
.
tokio-omnibus : A simpler way to include all above and, we expect, any future added tokio-* features in this crate.
cleaver
: Include the Cleaver
wrapper stream.
yield-stream
: Include the YieldStream
wrapper.
Macros§
- dispatch_
or_ permit - Attempt to dispatch a blocking operation, or otherwise obtain a permit and run on thread, returning the result of the closure.
Structs§
- Blocking
Permit - A scoped permit for blocking operations. When dropped (out of scope or manually), the permit is released.
- Blocking
Permit Future - A future which resolves to a
BlockingPermit
. - Canceled
- Error type returned as output from the
BlockingPermitFuture
orDispatched
futures if they are canceled. - Cleaver
- A
Stream
adapter that splits buffers from a source to a given, maximum length. - Dispatch
Pool - A specialized thread pool and queue for dispatching blocking (synchronous, long running) operations.
- Dispatch
Pool Builder - A builder for
DispatchPool
supporting an extenstive set of configuration options. - Dispatched
- A future type created by
dispatch_rx
. - Sync
Blocking Permit Future - A
Sync
wrapper available viaBlockingPermitFuture::make_sync
. - Yield
Stream - A
Stream
adapter that yields after everyPoll::Ready(Some(_))
result from its source.
Enums§
- Dispatch
Rx - Value returned by
dispatch_rx
.
Traits§
- Semaphorish
- Extension trait for uniform construction of the re-exported
Semaphore
types. - Splittable
- Trait for buffer types that may be split at a maximum length.
Functions§
- blocking_
permit_ future - Request a permit to perform a blocking operation on the current thread.
- deregister_
dispatch_ pool - Deregister and return any
DispatchPool
on the current thread. - dispatch
- Dispatch a blocking operation closure to a pool, if registered.
- dispatch_
rx - Dispatch a blocking operation closure to a registered pool, returning a future for awaiting the result.
- is_
dispatch_ pool_ registered - Return true if a DispatchPool is registered to the current thread.
- register_
dispatch_ pool - Register a
DispatchPool
on the calling thread.
Type Aliases§
- Semaphore
- An async-aware semaphore for constraining the number of concurrent blocking operations.