refactor: Replace Context::nosync flag with internal functions taking enum Sync (#4817)

This commit is contained in:
iequidoo
2023-10-29 23:24:15 -03:00
committed by iequidoo
parent 168021523f
commit 6cd7296001
6 changed files with 80 additions and 64 deletions

View File

@@ -173,7 +173,6 @@ impl ContextBuilder {
#[derive(Clone, Debug)]
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
nosync: bool,
}
impl Deref for Context {
@@ -393,34 +392,11 @@ impl Context {
let ctx = Context {
inner: Arc::new(inner),
nosync: false,
};
Ok(ctx)
}
/// Returns a `Context` in which sending sync messages must be skipped. `Self::unwrap_nosync()`
/// should be used to check this.
pub(crate) fn nosync(&self) -> Self {
Self {
inner: self.inner.clone(),
nosync: true,
}
}
/// Checks if sending sync messages must be skipped. Returns the original context and the result
/// of the check. If it's `true`, calls to [`Self::add_sync_item()`] mustn't be done to prevent
/// extra/recursive synchronisation.
pub(crate) fn unwrap_nosync(&self) -> (Self, bool) {
(
Self {
inner: self.inner.clone(),
nosync: false,
},
self.nosync,
)
}
/// Starts the IO scheduler.
pub async fn start_io(&mut self) {
if !self.is_configured().await.unwrap_or_default() {