qubit_dcl/double_checked/
executor_lock_builder.rs1use std::marker::PhantomData;
15
16use qubit_function::Tester;
17
18use super::{
19 ExecutionLogger,
20 executor_ready_builder::ExecutorReadyBuilder,
21};
22use crate::lock::Lock;
23
24#[derive(Clone)]
34pub struct ExecutorLockBuilder<L, T> {
35 pub(in crate::double_checked) lock: L,
37
38 pub(in crate::double_checked) logger: ExecutionLogger,
40
41 pub(in crate::double_checked) catch_panics: bool,
43
44 pub(in crate::double_checked) _phantom: PhantomData<fn() -> T>,
46}
47
48impl<L, T> ExecutorLockBuilder<L, T>
49where
50 L: Lock<T>,
51{
52 #[inline]
54 pub fn log_unmet_condition(mut self, level: log::Level, message: impl Into<String>) -> Self {
55 self.logger.set_unmet_condition(Some(level), message);
56 self
57 }
58
59 #[inline]
61 pub fn disable_unmet_condition_logging(mut self) -> Self {
62 self.logger.disable_unmet_condition();
63 self
64 }
65
66 #[inline]
68 pub fn log_prepare_failure(
69 mut self,
70 level: log::Level,
71 message_prefix: impl Into<String>,
72 ) -> Self {
73 self.logger.set_prepare_failure(Some(level), message_prefix);
74 self
75 }
76
77 #[inline]
79 pub fn disable_prepare_failure_logging(mut self) -> Self {
80 self.logger.disable_prepare_failure();
81 self
82 }
83
84 #[inline]
86 pub fn log_prepare_commit_failure(
87 mut self,
88 level: log::Level,
89 message_prefix: impl Into<String>,
90 ) -> Self {
91 self.logger
92 .set_prepare_commit_failure(Some(level), message_prefix);
93 self
94 }
95
96 #[inline]
98 pub fn disable_prepare_commit_failure_logging(mut self) -> Self {
99 self.logger.disable_prepare_commit_failure();
100 self
101 }
102
103 #[inline]
105 pub fn log_prepare_rollback_failure(
106 mut self,
107 level: log::Level,
108 message_prefix: impl Into<String>,
109 ) -> Self {
110 self.logger
111 .set_prepare_rollback_failure(Some(level), message_prefix);
112 self
113 }
114
115 #[inline]
117 pub fn disable_prepare_rollback_failure_logging(mut self) -> Self {
118 self.logger.disable_prepare_rollback_failure();
119 self
120 }
121
122 #[inline]
136 pub fn when<Tst>(self, tester: Tst) -> ExecutorReadyBuilder<L, T>
137 where
138 Tst: Tester + Send + Sync + 'static,
139 {
140 ExecutorReadyBuilder {
141 lock: self.lock,
142 tester: tester.into_arc(),
143 logger: self.logger,
144 prepare_action: None,
145 rollback_prepare_action: None,
146 commit_prepare_action: None,
147 catch_panics: self.catch_panics,
148 _phantom: PhantomData,
149 }
150 }
151
152 #[inline]
154 pub fn catch_panics(mut self) -> Self {
155 self.catch_panics = true;
156 self
157 }
158
159 #[inline]
162 pub fn set_catch_panics(mut self, catch_panics: bool) -> Self {
163 self.catch_panics = catch_panics;
164 self
165 }
166
167 #[inline]
169 pub fn disable_catch_panics(mut self) -> Self {
170 self.catch_panics = false;
171 self
172 }
173}