vortex_io/runtime/
blocking.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use futures::Stream;
5
6use crate::runtime::Handle;
7
8/// A generic API blocking entry points to runtimes.
9pub trait BlockingRuntime {
10    /// Associated type for the blocking iterator returned by `block_on_stream`.
11    type BlockingIterator<'a, R: 'a>: Iterator<Item = R> + 'a;
12
13    /// Returns a handle to the runtime.
14    fn handle(&self) -> Handle;
15
16    /// Runs a future to completion on the runtime, blocking the current thread until it completes.
17    ///
18    /// The future is provided a [`Handle`] to the runtime so that it may spawn additional tasks
19    /// to be executed concurrently.
20    fn block_on<Fut, R>(&self, fut: Fut) -> R
21    where
22        Fut: Future<Output = R>;
23
24    /// Returns an iterator wrapper around a stream, blocking the current thread for each item.
25    fn block_on_stream<'a, S, R>(&self, stream: S) -> Self::BlockingIterator<'a, R>
26    where
27        S: Stream<Item = R> + Send + 'a,
28        R: Send + 'a;
29}