feat: isLocked
This commit is contained in:
parent
fe21a2e7ab
commit
27cb8550ba
@ -2,7 +2,8 @@ module Data.Async.Class where
|
|||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
import Data.Maybe (Maybe)
|
import Data.Foldable (for_)
|
||||||
|
import Data.Maybe (Maybe, isNothing)
|
||||||
import Effect.Aff.Class (class MonadAff)
|
import Effect.Aff.Class (class MonadAff)
|
||||||
|
|
||||||
-- | Acquire a lock that guarantees access to mutable state
|
-- | Acquire a lock that guarantees access to mutable state
|
||||||
@ -32,6 +33,13 @@ class AsyncStateLock m lock | lock -> m where
|
|||||||
-- | `unlock` has been invoked.
|
-- | `unlock` has been invoked.
|
||||||
unlock :: forall async a. MonadAff async => m a -> lock a -> async Unit
|
unlock :: forall async a. MonadAff async => m a -> lock a -> async Unit
|
||||||
|
|
||||||
|
-- | Returns whether a lock is currently held
|
||||||
|
isLocked :: forall async a l g. MonadAff async => AsyncStateLock l g => l a -> async Boolean
|
||||||
|
isLocked l = do
|
||||||
|
guard :: Maybe (g a) <- tryLock l
|
||||||
|
for_ guard (unlock l)
|
||||||
|
pure $ isNothing guard
|
||||||
|
|
||||||
-- | A lock type that supports writing data to the mutable state.
|
-- | A lock type that supports writing data to the mutable state.
|
||||||
-- |
|
-- |
|
||||||
-- | Writable locks must also be Readable.
|
-- | Writable locks must also be Readable.
|
||||||
|
Loading…
Reference in New Issue
Block a user