From 0bcbb5434e664dffc7b6ba3e5ff445632cf644e2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 25 Feb 2020 11:35:35 +0100 Subject: [PATCH] cleanup unused module Signed-off-by: Wolfgang Bumiller --- src/tools/async_mutex.rs | 46 ---------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/tools/async_mutex.rs diff --git a/src/tools/async_mutex.rs b/src/tools/async_mutex.rs deleted file mode 100644 index eeaa2af3..00000000 --- a/src/tools/async_mutex.rs +++ /dev/null @@ -1,46 +0,0 @@ -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; - -use failure::Error; -use futures::future::FutureExt; -use tokio::sync::Lock as TokioLock; - -pub use tokio::sync::LockGuard as AsyncLockGuard; - -pub struct AsyncMutex(TokioLock); - -unsafe impl Sync for AsyncMutex {} - -impl AsyncMutex { - pub fn new(value: T) -> Self { - Self(TokioLock::new(value)) - } - - pub fn lock(&self) -> LockFuture { - let mut lock = self.0.clone(); - LockFuture { - lock: async move { lock.lock().await }.boxed(), - } - } - - // FIXME: remove Result<> from this. - pub fn new_locked(value: T) -> Result<(Self, AsyncLockGuard), Error> { - let mut this = Self::new(value); - let guard = futures::executor::block_on(this.0.lock()); - Ok((this, guard)) - } -} - -/// Represents a lock to be held in the future: -pub struct LockFuture { - lock: Pin> + Send + 'static>>, -} - -impl Future for LockFuture { - type Output = AsyncLockGuard; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - self.lock.poll_unpin(cx) - } -}