qubit_executor/task/task_result_handle.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use super::{
11 TaskResult,
12 try_get::TryGet,
13};
14
15/// Common interface for handles that expose a submitted task's final result.
16pub trait TaskResultHandle<R, E>: Send {
17 /// Returns whether the task has installed a terminal state.
18 ///
19 /// # Returns
20 ///
21 /// `true` after the task has reached a terminal lifecycle state. Result
22 /// publication to the handle may still be racing with this observation.
23 fn is_done(&self) -> bool;
24
25 /// Blocks until the task produces its final result.
26 ///
27 /// # Returns
28 ///
29 /// The final task result. If the completion endpoint is dropped without
30 /// publishing a result, a dropped-result error is reported.
31 fn get(self) -> TaskResult<R, E>
32 where
33 Self: Sized;
34
35 /// Attempts to retrieve the final result without blocking.
36 ///
37 /// # Returns
38 ///
39 /// [`TryGet::Ready`] when a result is available, otherwise
40 /// [`TryGet::Pending`] containing the original handle.
41 fn try_get(self) -> TryGet<Self, R, E>
42 where
43 Self: Sized;
44}