Skip to main content

DataAsyncReducer

Trait DataAsyncReducer 

Source
pub trait DataAsyncReducer {
    type Channel;
    type Action;

    // Required method
    async fn async_reduce(
        _radio: &mut Radio<Self, Self::Channel>,
        _action: Self::Action,
    ) -> ChannelSelection<Self::Channel>
       where Self::Channel: RadioChannel<Self>,
             Self: Sized;
}
Available on crate feature radio only.
Expand description

Define asynchronous actions for shared state, dispatched with RadioAsyncReducer.

Unlike DataReducer, this reducer receives a radio handle so state borrows can be scoped around asynchronous work instead of held across await points.

Required Associated Types§

Source

type Channel

Notification channel type used by this state’s radio station.

Source

type Action

Action accepted by this reducer.

Required Methods§

Source

async fn async_reduce( _radio: &mut Radio<Self, Self::Channel>, _action: Self::Action, ) -> ChannelSelection<Self::Channel>
where Self::Channel: RadioChannel<Self>, Self: Sized,

Process an action asynchronously and select the final notification channel.

Use Radio::write_silently for mutations that should only notify when RadioAsyncReducer::async_apply processes the returned selection. Ordinary writes still send their own notifications. Release all read and write guards before awaiting so other tasks can access the state.

Returning ChannelSelection::Silence skips the final notification but does not undo state changes or notifications already sent by writes.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§