Struct near_async::test_loop::delay_sender::DelaySender

source ·
pub struct DelaySender<Event>(/* private fields */);
Expand description

Interface to send an event with a delay (in virtual time). It can be converted to a Sender for any message type that can be converted into the event type, so that a DelaySender given by the test loop may be passed to production code that expects a Sender.

Implementations§

source§

impl<Event> DelaySender<Event>

source

pub fn new(inner: impl Fn(Event, Duration) + Send + Sync + 'static) -> Self

source

pub fn send_with_delay(&self, event: Event, delay: Duration)

source

pub fn with_additional_delay(&self, delay: Duration) -> DelaySender<Event>
where Event: 'static,

source

pub fn narrow<InnerEvent>(self) -> DelaySender<InnerEvent>
where Event: From<InnerEvent> + 'static,

source

pub fn into_wrapped_multi_sender<M: 'static, S: 'static>(self) -> S
where Self: IntoSender<M>, BreakApart<M>: IntoMultiSender<S>,

A shortcut for a common use case, where we use an enum message to represent all the possible messages that a multisender may be used to send.

This assumes that S is a multisender with the derive #[derive(MultiSendMessage, ...)], which creates the enum MyMultiSenderMessage (where MyMultiSender is the name of the struct being derived from).

To use, first include in the test loop event enum a case for MyMultiSenderMessage. Then, call this function to get a multisender, like builder.wrapped_multi_sender<MyMultiSenderMessage, MyMultiSender>().

source

pub fn into_delayed_action_runner<InnerData>( self, shutting_down: Arc<AtomicBool>, ) -> TestLoopDelayedActionRunner<InnerData>
where Event: From<TestLoopDelayedActionEvent<InnerData>> + 'static,

source

pub fn into_future_spawner(self) -> TestLoopFutureSpawner
where Event: From<Arc<TestLoopTask>> + 'static,

Returns a FutureSpawner that can be used to spawn futures into the loop.

source

pub fn into_async_computation_spawner( self, artificial_delay: impl Fn(&str) -> Duration + Send + Sync + 'static, ) -> TestLoopAsyncComputationSpawner
where Event: From<TestLoopAsyncComputationEvent> + 'static,

Returns an AsyncComputationSpawner that can be used to spawn async computation into the loop. The artificial_delay allows the test to determine an artificial delay that the computation should take, based on the name of the computation.

source§

impl<Event: 'static> DelaySender<(usize, Event)>

source

pub fn for_index(self, index: usize) -> DelaySender<Event>

Converts a multi-instance sender to a single-instance sender.

Trait Implementations§

source§

impl<Data: 'static, Event: From<AdhocEvent<Data>> + 'static> AdhocEventSender<Data> for DelaySender<Event>

source§

fn send_adhoc_event( &self, description: &str, f: impl FnOnce(&mut Data) + Send + 'static, )

source§

fn schedule_adhoc_event( &self, description: &str, f: impl FnOnce(&mut Data) + Send + 'static, delay: Duration, )

source§

impl<Message, Event: From<Message> + 'static> CanSend<Message> for DelaySender<Event>

source§

fn send(&self, message: Message)

source§

impl<Event> Clone for DelaySender<Event>

Custom implementation because #derive wouldn’t work if Event does not Clone.

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Event> Freeze for DelaySender<Event>

§

impl<Event> !RefUnwindSafe for DelaySender<Event>

§

impl<Event> Send for DelaySender<Event>

§

impl<Event> Sync for DelaySender<Event>

§

impl<Event> Unpin for DelaySender<Event>

§

impl<Event> !UnwindSafe for DelaySender<Event>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> FutureSpawnerExt for T
where T: FutureSpawner,

source§

fn spawn<F>(&self, description: &'static str, f: F)
where F: Future<Output = ()> + Send + 'static,

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<A, B> IntoMultiSender<B> for A
where B: MultiSenderFrom<A>,

source§

fn as_multi_sender(self: &Arc<A>) -> B

source§

fn into_multi_sender(self) -> B

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<M, T> IntoSender<M> for T
where T: CanSend<M>,

source§

fn into_sender(self) -> Sender<M>

This allows conversion of an owned CanSend into a Sender.
source§

fn as_sender(self: &Arc<T>) -> Sender<M>

This allows conversion of a reference-counted CanSend into a Sender.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<M, R, A> SendAsync<M, R> for A
where R: Send + 'static, A: CanSend<MessageWithCallback<M, R>> + ?Sized,

source§

fn send_async( &self, message: M, ) -> Pin<Box<dyn Future<Output = Result<R, AsyncSendError>> + Send>>

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<R, T> TryIntoOrSelf<R> for T
where T: TryInto<R, Error = T>,

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more