pub struct BoundedSpawner<P: Send + 'static> { /* private fields */ }Expand description
通用有界并发原语:有界 mpsc(cap=K) + N 个常驻 worker + 溢出策略。
Implementations§
Source§impl<P: Send + 'static> BoundedSpawner<P>
impl<P: Send + 'static> BoundedSpawner<P>
Sourcepub fn new<F, Fut>(
concurrency: usize,
queue_cap: usize,
overflow: Overflow,
reply_tx: UnboundedSender<Tick>,
run: F,
) -> Selfwhere
F: Fn(Option<Correlation>, P) -> Fut + Clone + Send + 'static,
Fut: Future<Output = PortOutcome> + Send + 'static,
pub fn new<F, Fut>(
concurrency: usize,
queue_cap: usize,
overflow: Overflow,
reply_tx: UnboundedSender<Tick>,
run: F,
) -> Selfwhere
F: Fn(Option<Correlation>, P) -> Fut + Clone + Send + 'static,
Fut: Future<Output = PortOutcome> + Send + 'static,
构造:concurrency=N 个 worker;queue_cap=K;run = 每条 job 的 I/O 执行体
(async 闭包,返回 PortOutcome,仅在 job.corr=Some 时回报)。
N 个 worker 共享单队列(竞争 recv);Persist 用 N=1 保写序。
Sourcepub fn new_observed<F, Fut>(
concurrency: usize,
queue_cap: usize,
overflow: Overflow,
reply_tx: UnboundedSender<Tick>,
sink: Arc<dyn AsyncMetricSink>,
pool: &'static str,
run: F,
) -> Selfwhere
F: Fn(Option<Correlation>, P) -> Fut + Clone + Send + 'static,
Fut: Future<Output = PortOutcome> + Send + 'static,
pub fn new_observed<F, Fut>(
concurrency: usize,
queue_cap: usize,
overflow: Overflow,
reply_tx: UnboundedSender<Tick>,
sink: Arc<dyn AsyncMetricSink>,
pool: &'static str,
run: F,
) -> Selfwhere
F: Fn(Option<Correlation>, P) -> Fut + Clone + Send + 'static,
Fut: Future<Output = PortOutcome> + Send + 'static,
构造带指标的工作池,并在公开 seam 上保持与 new 相同的执行语义。
Sourcepub async fn submit(&self, job: Job<P>)
pub async fn submit(&self, job: Job<P>)
入队一条 job。
- Block:
send().await,满则阻塞泵(背压传导回 tick_tx)。 - DropNewest:try_send,满则丢本条(最新) + warn(泵不阻塞)。
Sourcepub async fn shutdown_with_timeout(self, limit: Duration) -> bool
pub async fn shutdown_with_timeout(self, limit: Duration) -> bool
有上限 graceful drain(fix/lifecycle-net-decouple):drop tx → join,全程封顶 limit。
限内全 join 完成 → true;超时 → abort 残留 worker(放弃在途 job)+ false。
为何需上限:必达 Http reqwest 单条可卡满网络 timeout(连不上 ~30s),无上限会让
helix_destroy graceful drain 等满。不丢保证由乐观态持久化(status=Sending) + 重连重发
对账承担,不由「drain 必等满网络」承担——abort 在途 Http 不丢数据(消息仍 status=Sending
留库,靠重连兜底)。完整语义见 engine.rs 五不变量⑤ + driver AGENTS.md。
Auto Trait Implementations§
impl<P> !RefUnwindSafe for BoundedSpawner<P>
impl<P> !UnwindSafe for BoundedSpawner<P>
impl<P> Freeze for BoundedSpawner<P>
impl<P> Send for BoundedSpawner<P>
impl<P> Sync for BoundedSpawner<P>
impl<P> Unpin for BoundedSpawner<P>
impl<P> UnsafeUnpin for BoundedSpawner<P>where
Sender<QueuedJob<P>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request