Struct actix::sync::SyncArbiter [−][src]
pub struct SyncArbiter<A> where
A: Actor<Context = SyncContext<A>>, { /* fields omitted */ }
Expand description
SyncArbiter provides the resources for a single Sync Actor to run on a dedicated thread or threads. This is generally used for CPU bound concurrent workloads. It’s important to note, that the SyncArbiter generates a single address for the pool of hosted Sync Actors. Any message sent to this Address, will be operated on by a single Sync Actor from the pool.
Sync Actors have a different lifecycle compared to Actors on the System
Arbiter. For more, see SyncContext
.
Examples
use actix::prelude::*; struct Fibonacci(pub u32); struct SyncActor; impl Actor for SyncActor { // It's important to note that you use "SyncContext" here instead of "Context". type Context = SyncContext<Self>; } impl Handler<Fibonacci> for SyncActor { type Result = Result<u64, ()>; fn handle(&mut self, msg: Fibonacci, _: &mut Self::Context) -> Self::Result { if msg.0 == 0 { Err(()) } else if msg.0 == 1 { Ok(1) } else { let mut i = 0; let mut sum = 0; let mut last = 0; let mut curr = 1; while i < msg.0 - 1 { sum = last + curr; last = curr; curr = sum; i += 1; } Ok(sum) } } } fn main() { System::new().block_on(async { // Start the SyncArbiter with 2 threads, and receive the address of the Actor pool. let addr = SyncArbiter::start(2, || SyncActor); // send 5 messages for n in 5..10 { // As there are 2 threads, there are at least 2 messages always being processed // concurrently by the SyncActor. addr.do_send(Fibonacci(n)); } }); }
Implementations
Start a new SyncArbiter
with specified number of worker threads.
Returns a single address of the started actor. A single address is
used to communicate to the actor(s), and messages are handled by
the next available Actor in the SyncArbiter
.
Trait Implementations
Called after an actor is in Actor::Stopping
state. Read more
Start a new asynchronous actor, returning its address. Read more
Construct and start a new asynchronous actor, returning its address. Read more
fn start_in_arbiter<F>(wrk: &ArbiterHandle, f: F) -> Addr<Self> where
Self: Actor<Context = Context<Self>>,
F: FnOnce(&mut Context<Self>) -> Self + Send + 'static,
[src]
fn start_in_arbiter<F>(wrk: &ArbiterHandle, f: F) -> Addr<Self> where
Self: Actor<Context = Context<Self>>,
F: FnOnce(&mut Context<Self>) -> Self + Send + 'static,
[src]Start new actor in arbiter’s thread.
Auto Trait Implementations
impl<A> !RefUnwindSafe for SyncArbiter<A>
impl<A> Send for SyncArbiter<A>
impl<A> Sync for SyncArbiter<A>
impl<A> Unpin for SyncArbiter<A>
impl<A> !UnwindSafe for SyncArbiter<A>
Blanket Implementations
Mutably borrows from an owned value. Read more
Map this future’s output to a different type, returning a new future of the resulting type. Read more
Map this future’s output to a different type, returning a new future of the resulting type. Read more
Chain on a computation for when a future finished, passing the result of
the future to the provided closure f
. Read more
Wrap this future in an Either
future, making it the left-hand variant
of that Either
. Read more
Wrap this future in an Either
future, making it the right-hand variant
of that Either
. Read more
Convert this future into a single element stream. Read more
Flatten the execution of this future when the output of this future is itself another future. Read more
Flatten the execution of this future when the successful result of this future is a stream. Read more
Fuse a future such that poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read more
Do something with the output of a future before passing it on. Read more
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>. Read more
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>. Read more
A convenience for calling Future::poll
on Unpin
future types.
Evaluates and consumes the future, returning the resulting output if
the future is ready after the first call to Future::poll
. Read more
into_future
)The output that the future will produce on completion.
type Future = F
type Future = F
into_future
)Which kind of future are we turning this into?
into_future
)Creates a future from a value.
type Future = FutureWrap<F, A>
type Future = FutureWrap<F, A>
The future that this type can be converted into.
Convert normal future to a ActorFuture