packages feed

monad-schedule 1.6 → 1.7

raw patch · 3 files changed

+14/−10 lines, 3 filesdep ~time-domain

Dependency ranges changed: time-domain

Files

monad-schedule.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: monad-schedule-version: 1.6+version: 1.7 license: MIT license-file: LICENSE author: Manuel Bärenz@@ -28,7 +28,7 @@     free >=5.1 && <5.3,     operational ^>=0.2.4,     stm ^>=2.5,-    time-domain ^>=1.6,+    time-domain ^>=1.7,     transformers >=0.5 && <0.7,    if flag(dev)
src/Control/Monad/Schedule/Class.hs view
@@ -50,9 +50,10 @@ 'schedule' thus can be thought of as a concurrency-utilizing version of 'sequence'. -} class MonadSchedule m where-  -- | Run the actions concurrently,-  --   and return the result of the first finishers,-  --   together with completions for the unfinished actions.+  {- | Run the actions concurrently,+  and return the result of the first finishers,+  together with completions for the unfinished actions.+  -}   schedule :: NonEmpty (m a) -> m (NonEmpty a, [m a])  {- | Keeps 'schedule'ing actions until all are finished.
test/Trans.hs view
@@ -31,6 +31,9 @@ -- HUnit import Test.HUnit hiding (Test) +-- time-domain+import Data.TimeDomain (Seconds (..))+ -- monad-schedule import Control.Monad.Schedule.Class (scheduleAndFinish) import Control.Monad.Schedule.Trans@@ -89,7 +92,7 @@                         threadNames scripts     , testCase "Regression example from rhine"         $ assertRunsLike-          (mapM_ wait <$> [[5, 5] :: [Integer], [3, 3, 3]])+          (mapM_ (wait . Seconds) <$> [[5, 5] :: [Integer], [3, 3, 3]])         $ Waited           <$> differences             [ 3@@ -103,7 +106,7 @@           let individualWaits = fmap getPositive <$> waits               individualTimes = scanl1 (+) <$> individualWaits               allWaits = map Waited $ filter (> 0) $ differences $ sort $ concat individualTimes-              program = mapM wait <$> individualWaits+              program = mapM (wait . Seconds) <$> individualWaits            in runMySchedule program === allWaits     ] @@ -124,13 +127,13 @@   | Waited Integer   deriving (Eq, Show) -type MySchedule a = ScheduleT Integer (Writer [Event]) a+type MySchedule a = ScheduleT (Seconds Integer) (Writer [Event]) a  myLog :: String -> MySchedule () myLog = lift . tell . pure . Log  runMySchedule :: NonEmpty (MySchedule a) -> [Event]-runMySchedule = execWriter . runScheduleT (tell . pure . Waited) . scheduleAndFinish+runMySchedule = execWriter . runScheduleT (tell . pure . Waited . getSeconds) . scheduleAndFinish  differences :: [Integer] -> [Integer] differences times = uncurry (-) <$> zip times (0 : times)@@ -165,7 +168,7 @@  interpretScript :: Script -> MySchedule () interpretScript Script {..} = do-  let perform interval = myLog threadName >> wait (getPositive interval)+  let perform interval = myLog threadName >> wait (Seconds (getPositive interval))   mapM_ perform prefix   forever $ mapM_ perform loop