Skip to main content

TaskSink

Trait TaskSink 

Source
pub trait TaskSink<Args, Kind>: Backend {
    // Required methods
    fn start_send(
        self: Pin<&mut Self>,
        item: Task<Args>,
    ) -> Result<(), TaskSinkError<Self::Error>>;
    fn poll_ready(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<(), TaskSinkError<Self::Error>>>;
    fn poll_flush(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<(), TaskSinkError<Self::Error>>>;
    fn poll_close(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<(), TaskSinkError<Self::Error>>>;
    fn push(
        &mut self,
        task: Args,
    ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send;
    fn push_bulk(
        &mut self,
        tasks: Vec<Args>,
    ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send;
    fn push_stream(
        &mut self,
        tasks: impl Stream<Item = Args> + Unpin + Send,
    ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send;
    fn push_task(
        &mut self,
        task: Task<Args>,
    ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send;
    fn push_all(
        &mut self,
        tasks: impl Stream<Item = Task<Args>> + Unpin + Send,
    ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send;
}
Expand description

A sink for submitting tasks to a backend.

TaskSink provides two levels of task submission:

§Task types

Args is the type accepted by the backend’s high-level submission methods, while Task<Args> represents a fully constructed task with its associated task metadata.

Kind identifies the kind of backend being targeted.

Required Methods§

Source

fn start_send( self: Pin<&mut Self>, item: Task<Args>, ) -> Result<(), TaskSinkError<Self::Error>>

Begins sending a task to the sink.

This method is the counterpart to Sink::start_send. The caller must ensure that the sink is ready to accept the task by successfully polling Sink::poll_ready first.

The task may be buffered internally and may not be persisted until Sink::poll_flush is driven to completion.

Source

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), TaskSinkError<Self::Error>>>

Polls the sink until it is ready to accept another task.

Returns Poll::Ready when a subsequent call to start_send may be made.

When Poll::Pending is returned, the sink is not currently ready and the caller must wait for the provided waker to be notified before polling again.

Source

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), TaskSinkError<Self::Error>>>

Polls the sink until all previously submitted tasks have been flushed.

A successful Poll::Ready indicates that all tasks accepted by the sink have been flushed to the backend.

This does not close the sink; additional tasks may be submitted after a successful flush.

Source

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), TaskSinkError<Self::Error>>>

Polls the sink until it has been closed.

Once closed, the sink must no longer accept new tasks.

Implementations should flush any pending tasks before completing the close operation.

Source

fn push( &mut self, task: Args, ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send

Pushes a single task into the backend.

The returned future completes when the task has been accepted by the backend.

Source

fn push_bulk( &mut self, tasks: Vec<Args>, ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send

Pushes multiple tasks into the backend.

Implementations may use a backend-specific bulk operation to submit the tasks more efficiently than calling TaskSink::push for each task.

Source

fn push_stream( &mut self, tasks: impl Stream<Item = Args> + Unpin + Send, ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send

Pushes tasks from a stream into the backend.

The stream is consumed until it is exhausted or an error occurs. Implementations may process the stream incrementally rather than collecting all tasks before submission.

Source

fn push_task( &mut self, task: Task<Args>, ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send

Pushes a fully constructed task into the backend.

Use this method when the task has already been constructed and its metadata should be preserved rather than generated by the backend.

Source

fn push_all( &mut self, tasks: impl Stream<Item = Task<Args>> + Unpin + Send, ) -> impl Future<Output = Result<(), TaskSinkError<Self::Error>>> + Send

Pushes fully constructed tasks from a stream into the backend.

The stream is consumed until it is exhausted or an error occurs. Implementations may process the stream incrementally rather than collecting all tasks before submission.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<Args, S, E, C> TaskSink<Args, Durable> for S
where S: Sink<Task<<C as Codec<Args>>::Compact>, Error = E> + Unpin + Backend<Error = E> + WireFormatBackend<Codec = C> + BackendConfig<Args = Args, Kind = Durable> + Send, Args: Send, <C as Codec<Args>>::Compact: Send, C: Codec<Args> + Clone + Send + Sync, E: Send, <C as Codec<Args>>::Error: Error + Send + Sync + 'static,

Source§

impl<Args, S, E> TaskSink<Args, Ephemeral> for S
where S: Unpin + Backend<Error = E> + BackendConfig<Args = Args, Kind = Ephemeral> + Sink<Task<Args>, Error = E> + Send, Args: Send, E: Send,