Skip to main content

runtime/backlog/
config.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! How a table is made and configured: the window its callers block for
7//! before a command is handed to the background
8//! (`crates/runtime/spec/Backlog.lean` §8-28), where a command's output
9//! goes while it is inside that window (the same part, §8-28-3), and what
10//! shares every run it starts asks for
11//! (`crates/runtime/spec/Tools/Exec.lean` D29). The table itself, what it
12//! carries and how it ends, is the module above.
13
14use super::{Backlog, PollBudget, RunAffinity, Scratch, Shares, Sink};
15
16impl Backlog {
17    /// Requests this affinity for each run's job. Configure before the
18    /// first command: a run keeps its first job's limits (D49).
19    /// Unsupported platforms and refused requests report `Os` and keep
20    /// the command's own exit result.
21    #[must_use]
22    pub fn with_affinity(self, affinity: RunAffinity) -> Backlog {
23        Backlog { affinity, ..self }
24    }
25
26    #[must_use]
27    pub fn new() -> Backlog {
28        Backlog::default()
29    }
30
31    /// A table whose callers block for this window before a command is
32    /// handed to the background.
33    #[must_use]
34    pub fn with_window(window: PollBudget) -> Backlog {
35        Backlog {
36            table: std::sync::Arc::default(),
37            scratch: Scratch::open(),
38            window,
39            sink: None,
40            shares: Shares::Unset,
41            affinity: RunAffinity::Os,
42        }
43    }
44
45    /// The same table, handing what a command writes to `sink` while
46    /// the command is still inside its window (`crates/runtime/spec/Backlog.lean` §8-28-3).
47    #[must_use]
48    pub fn with_sink(self, sink: Sink) -> Backlog {
49        Backlog {
50            sink: Some(sink),
51            ..self
52        }
53    }
54}