pub struct IntervalFunc<A: Actor> { /* private fields */ }
Expand description
An ActorStream
that periodically runs a function in the actor’s context.
Unless you specifically need access to the future, use Context::run_interval
instead.
use std::time::Duration;
use actix::prelude::*;
use actix::utils::IntervalFunc;
struct MyActor;
impl MyActor {
fn tick(&mut self, context: &mut Context<Self>) {
println!("tick");
}
}
impl Actor for MyActor {
type Context = Context<Self>;
fn started(&mut self, context: &mut Context<Self>) {
// spawn an interval stream into our context
IntervalFunc::new(Duration::from_millis(100), Self::tick)
.finish()
.spawn(context);
}
}
Implementations§
Source§impl<A: Actor> IntervalFunc<A>
impl<A: Actor> IntervalFunc<A>
Sourcepub fn new<F>(interval: Duration, task: F) -> IntervalFunc<A>
pub fn new<F>(interval: Duration, task: F) -> IntervalFunc<A>
Constructs an IntervalFunc
using the given interval
duration and task
function.
Trait Implementations§
Source§impl<A: Actor> ActorStream<A> for IntervalFunc<A>
impl<A: Actor> ActorStream<A> for IntervalFunc<A>
impl<'__pin, A: Actor> Unpin for IntervalFunc<A>where
PinnedFieldsOf<__Origin<'__pin, A>>: Unpin,
Auto Trait Implementations§
impl<A> !Freeze for IntervalFunc<A>
impl<A> !RefUnwindSafe for IntervalFunc<A>
impl<A> !Send for IntervalFunc<A>
impl<A> !Sync for IntervalFunc<A>
impl<A> !UnwindSafe for IntervalFunc<A>
Blanket Implementations§
Source§impl<A, S> ActorStreamExt<A> for Swhere
S: ActorStream<A>,
A: Actor,
impl<A, S> ActorStreamExt<A> for Swhere
S: ActorStream<A>,
A: Actor,
Source§fn map<F, U>(self, f: F) -> Map<Self, F>
fn map<F, U>(self, f: F) -> Map<Self, F>
Maps this stream’s items to a different type, returning a new stream of
the resulting type. Read more
Source§fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
Computes from this stream’s items new items of a different type using
an asynchronous closure. Read more
Source§fn fold<F, Fut>(
self,
init: Fut::Output,
f: F,
) -> Fold<Self, F, Fut, Fut::Output>
fn fold<F, Fut>( self, init: Fut::Output, f: F, ) -> Fold<Self, F, Fut, Fut::Output>
Execute an accumulating asynchronous computation over a stream,
collecting all the values into one final result. Read more
Source§fn take_while<F, Fut>(self, f: F) -> TakeWhile<Self, Self::Item, F, Fut>
fn take_while<F, Fut>(self, f: F) -> TakeWhile<Self, Self::Item, F, Fut>
Take elements from this stream while the provided asynchronous predicate
resolves to
true
. Read moreSource§fn skip_while<F, Fut>(self, f: F) -> SkipWhile<Self, Self::Item, F, Fut>
fn skip_while<F, Fut>(self, f: F) -> SkipWhile<Self, Self::Item, F, Fut>
Skip elements on this stream while the provided asynchronous predicate
resolves to
true
. Read moreSource§fn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
fn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
Add timeout to stream. Read more
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