diff options
Diffstat (limited to 'Assistant/Pushes.hs')
-rw-r--r-- | Assistant/Pushes.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Assistant/Pushes.hs b/Assistant/Pushes.hs index f411dda07..649975fd1 100644 --- a/Assistant/Pushes.hs +++ b/Assistant/Pushes.hs @@ -10,6 +10,7 @@ module Assistant.Pushes where import Common.Annex import Control.Concurrent.STM +import Control.Concurrent.MSampleVar import Data.Time.Clock import qualified Data.Map as M @@ -17,6 +18,9 @@ import qualified Data.Map as M type PushMap = M.Map Remote UTCTime type FailedPushMap = TMVar PushMap +{- Used to notify about successful pushes. -} +newtype PushNotifier = PushNotifier (MSampleVar ()) + {- The TMVar starts empty, and is left empty when there are no - failed pushes. This way we can block until there are some failed pushes. -} @@ -44,3 +48,12 @@ changeFailedPushMap v a = atomically $ store m | m == M.empty = noop | otherwise = putTMVar v $! m + +newPushNotifier :: IO PushNotifier +newPushNotifier = PushNotifier <$> newEmptySV + +notifyPush :: PushNotifier -> IO () +notifyPush (PushNotifier sv) = writeSV sv () + +waitPush :: PushNotifier -> IO () +waitPush (PushNotifier sv) = readSV sv |