use std::fmt::Display;
use qubit_function::{Callable, CallableWith, Runnable, RunnableWith};
use super::{
DoubleCheckedLockExecutor, ExecutionContext, executor_ready_builder::ExecutorReadyBuilder,
};
use crate::lock::Lock;
#[derive(Clone)]
pub struct DoubleCheckedLockReadyBuilder<L, T> {
pub(in crate::double_checked) inner: ExecutorReadyBuilder<L, T>,
}
impl<L, T> DoubleCheckedLockReadyBuilder<L, T>
where
L: Lock<T>,
{
#[inline]
pub fn log_unmet_condition(mut self, level: log::Level, message: impl Into<String>) -> Self {
self.inner = self.inner.log_unmet_condition(level, message);
self
}
#[inline]
pub fn disable_unmet_condition_logging(mut self) -> Self {
self.inner = self.inner.disable_unmet_condition_logging();
self
}
#[inline]
pub fn log_prepare_failure(
mut self,
level: log::Level,
message_prefix: impl Into<String>,
) -> Self {
self.inner = self.inner.log_prepare_failure(level, message_prefix);
self
}
#[inline]
pub fn disable_prepare_failure_logging(mut self) -> Self {
self.inner = self.inner.disable_prepare_failure_logging();
self
}
#[inline]
pub fn log_prepare_commit_failure(
mut self,
level: log::Level,
message_prefix: impl Into<String>,
) -> Self {
self.inner = self.inner.log_prepare_commit_failure(level, message_prefix);
self
}
#[inline]
pub fn disable_prepare_commit_failure_logging(mut self) -> Self {
self.inner = self.inner.disable_prepare_commit_failure_logging();
self
}
#[inline]
pub fn log_prepare_rollback_failure(
mut self,
level: log::Level,
message_prefix: impl Into<String>,
) -> Self {
self.inner = self
.inner
.log_prepare_rollback_failure(level, message_prefix);
self
}
#[inline]
pub fn disable_prepare_rollback_failure_logging(mut self) -> Self {
self.inner = self.inner.disable_prepare_rollback_failure_logging();
self
}
#[inline]
pub fn catch_panics(mut self) -> Self {
self.inner = self.inner.catch_panics();
self
}
#[inline]
pub fn set_catch_panics(mut self, catch_panics: bool) -> Self {
self.inner = self.inner.set_catch_panics(catch_panics);
self
}
#[inline]
pub fn disable_catch_panics(mut self) -> Self {
self.inner = self.inner.disable_catch_panics();
self
}
#[inline]
pub fn prepare<Rn, E>(mut self, prepare_action: Rn) -> Self
where
Rn: Runnable<E> + Send + 'static,
E: Display,
{
self.inner = self.inner.prepare(prepare_action);
self
}
#[inline]
pub fn rollback_prepare<Rn, E>(mut self, rollback_prepare_action: Rn) -> Self
where
Rn: Runnable<E> + Send + 'static,
E: Display,
{
self.inner = self.inner.rollback_prepare(rollback_prepare_action);
self
}
#[inline]
pub fn commit_prepare<Rn, E>(mut self, commit_prepare_action: Rn) -> Self
where
Rn: Runnable<E> + Send + 'static,
E: Display,
{
self.inner = self.inner.commit_prepare(commit_prepare_action);
self
}
#[inline]
pub fn build(self) -> DoubleCheckedLockExecutor<L, T> {
self.inner.build()
}
#[inline]
pub fn call<C, R, E>(self, task: C) -> ExecutionContext<R, E>
where
C: Callable<R, E>,
E: Display,
{
self.inner.build().call(task)
}
#[inline]
pub fn execute<Rn, E>(self, task: Rn) -> ExecutionContext<(), E>
where
Rn: Runnable<E>,
E: Display,
{
self.inner.build().execute(task)
}
#[inline]
pub fn call_with<C, R, E>(self, task: C) -> ExecutionContext<R, E>
where
C: CallableWith<T, R, E>,
E: Display,
{
self.inner.build().call_with(task)
}
#[inline]
pub fn execute_with<Rn, E>(self, task: Rn) -> ExecutionContext<(), E>
where
Rn: RunnableWith<T, E>,
E: Display,
{
self.inner.build().execute_with(task)
}
}