Skip to main content

turbo_tasks/
read_options.rs

1use crate::{ReadConsistency, ReadTracking, event::EventListener, manager::ReadCellTracking};
2
3/// What a read of a task's output or cell found.
4///
5/// The two "not available yet" cases are distinguished because the reader can act on them
6/// differently: a task that is only *scheduled* can be taken over and executed by the reader, while
7/// one that some worker is already executing can only be waited for — and finding that out without
8/// taking the scheduler's queue lock is the point of telling them apart.
9///
10/// The state is a **hint**: it is a snapshot, and a task can be picked up by a worker right after
11/// the read looked (a worker even pops a task off the queue before it marks it as started). Acting
12/// on a stale hint costs at most a failed claim, never correctness.
13pub enum ReadOutcome<T> {
14    /// The value is available.
15    Value(T),
16    /// The task is queued but no worker has started it, so the reader may take it out of the queue
17    /// and execute it itself. The listener fires when the task is done.
18    Scheduled(EventListener),
19    /// A worker is already executing the task; there is nothing to take over. The listener fires
20    /// when the task is done.
21    InProgress(EventListener),
22}
23
24#[derive(Clone, Copy, Debug, Default)]
25pub struct ReadCellOptions {
26    pub tracking: ReadCellTracking,
27    pub final_read_hint: bool,
28}
29
30#[derive(Clone, Copy, Debug, Default)]
31pub struct ReadOutputOptions {
32    pub tracking: ReadTracking,
33    pub consistency: ReadConsistency,
34}