diff options
-rw-r--r-- | src/BatchedRunner.hs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/BatchedRunner.hs b/src/BatchedRunner.hs index 83a704c..89dd3a8 100644 --- a/src/BatchedRunner.hs +++ b/src/BatchedRunner.hs @@ -31,7 +31,14 @@ makeRunner f n = do unless (fromMaybe False mayB) $ runnerLoop mv stopRunner :: Runner -> IO () -stopRunner (Runner mv) = atomically $ putTMVar mv True +stopRunner (Runner mv) = atomically $ do + mayB <- tryReadTMVar mv + case mayB of + -- if stopped/stopping, do nothing + Just True -> return () + -- if idle or working, block, such that the Runner has a chance to see that + -- it should fire before stopping + _ -> putTMVar mv True notifyRunner :: Runner -> IO () notifyRunner (Runner mv) = void $ atomically $ tryPutTMVar mv False |