Trait PersistentTask

Source
pub trait PersistentTask: 'static + Send {
    type State<'state>;
    type Input: 'static + Send;
    type Output: 'static + Send;

    const CHANNEL_CAPACITY: usize = 0usize;

    // Required methods
    fn init<'frame, 'life0, 'async_trait>(
        &'life0 mut self,
        frame: AsyncGcFrame<'frame>,
    ) -> Pin<Box<dyn Future<Output = JlrsResult<Self::State<'frame>>> + 'async_trait>>
       where Self: 'async_trait,
             'frame: 'async_trait,
             'life0: 'async_trait;
    fn run<'frame, 'state, 'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        frame: AsyncGcFrame<'frame>,
        state: &'life1 mut Self::State<'state>,
        input: Self::Input,
    ) -> Pin<Box<dyn Future<Output = Self::Output> + 'async_trait>>
       where Self: 'async_trait,
             'frame: 'async_trait,
             'state: 'async_trait + 'frame,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn exit<'frame, 'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _frame: AsyncGcFrame<'frame>,
        _state: &'life1 mut Self::State<'frame>,
    ) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>
       where Self: 'async_trait,
             'frame: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}

Provided Associated Constants§

Required Associated Types§

Source

type State<'state>

The type of the result which is returned if init completes successfully.

This data is provided to every call of run.

Source

type Input: 'static + Send

The type of the data that must be provided when calling this persistent through its handle.

Source

type Output: 'static + Send

The type of the result which is returned by run.

Required Methods§

Source

fn init<'frame, 'life0, 'async_trait>( &'life0 mut self, frame: AsyncGcFrame<'frame>, ) -> Pin<Box<dyn Future<Output = JlrsResult<Self::State<'frame>>> + 'async_trait>>
where Self: 'async_trait, 'frame: 'async_trait, 'life0: 'async_trait,

Initialize the task.

You can interact with Julia inside this method, the frame is not dropped until the task itself is dropped. This means that State can contain arbitrary Julia data rooted in this frame. This data is provided to every call to run.

Source

fn run<'frame, 'state, 'life0, 'life1, 'async_trait>( &'life0 mut self, frame: AsyncGcFrame<'frame>, state: &'life1 mut Self::State<'state>, input: Self::Input, ) -> Pin<Box<dyn Future<Output = Self::Output> + 'async_trait>>
where Self: 'async_trait, 'frame: 'async_trait, 'state: 'async_trait + 'frame, 'life0: 'async_trait, 'life1: 'async_trait,

Run the task.

This method takes an AsyncGcFrame, which lets you interact with Julia. It’s also provided with a mutable reference to its state and the input provided by the caller. While the state is mutable, it’s not possible to allocate a new Julia value in run and assign it to the state because the frame doesn’t live long enough.

See the trait docs for an example implementation.

Provided Methods§

Source

fn exit<'frame, 'life0, 'life1, 'async_trait>( &'life0 mut self, _frame: AsyncGcFrame<'frame>, _state: &'life1 mut Self::State<'frame>, ) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>
where Self: 'async_trait, 'frame: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Method that is called when all handles to the task have been dropped.

This method is called with the same frame as init.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§