[][src]Struct actix_web::actix::IntervalFunc

#[must_use = "future do nothing unless polled"]
pub struct IntervalFunc<A> where
    A: Actor
{ /* fields omitted */ }

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);
   }
}

Methods

impl<A> IntervalFunc<A> where
    A: Actor
[src]

pub fn new<F>(timeout: Duration, f: F) -> IntervalFunc<A> where
    F: FnMut(&mut A, &mut <A as Actor>::Context) + 'static, 
[src]

Creates a new IntervalFunc with the given interval duration.

Trait Implementations

impl<A> ActorStream for IntervalFunc<A> where
    A: Actor
[src]

type Item = ()

The type of item this stream will yield on success.

type Error = ()

The type of error this stream may generate.

type Actor = A

The actor within which this stream runs.

fn map<U, F>(self, f: F) -> StreamMap<Self, F> where
    F: FnMut(Self::Item, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U, 
[src]

Converts a stream of type T to a stream of type U.

fn map_err<E, F>(self, f: F) -> StreamMapErr<Self, F> where
    F: FnMut(Self::Error, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> E, 
[src]

Converts a stream of error type T to a stream of error type E.

fn then<F, U>(self, f: F) -> StreamThen<Self, F, U> where
    F: FnMut(Result<Self::Item, Self::Error>, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U,
    U: IntoActorFuture<Actor = Self::Actor>, 
[src]

Chain on a computation for when a value is ready, passing the resulting item to the provided closure f. Read more

fn and_then<F, U>(self, f: F) -> StreamAndThen<Self, F, U> where
    F: FnMut(Self::Item, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U,
    U: IntoActorFuture<Error = Self::Error, Actor = Self::Actor>, 
[src]

Chain on a computation for when a value is ready, passing the successful results to the provided closure f. Read more

fn fold<F, T, Fut>(self, init: T, f: F) -> StreamFold<Self, F, Fut, T> where
    F: FnMut(T, Self::Item, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> Fut,
    Fut: IntoActorFuture<Actor = Self::Actor, Item = T>,
    Self::Error: From<<Fut as IntoActorFuture>::Error>, 
[src]

Execute an accumulating computation over a stream, collecting all the values into one final result. Read more

fn timeout(self, timeout: Duration, err: Self::Error) -> StreamTimeout<Self> where
    Self::Error: Clone
[src]

Add timeout to stream. Read more

fn finish(self) -> StreamFinish<Self>[src]

Converts a stream to a future that resolves when stream finishes.

Auto Trait Implementations

impl<A> !Send for IntervalFunc<A>

impl<A> !Sync for IntervalFunc<A>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Erased for T