Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Avoid unnecessary use of run #358

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Test/StateMachine/Sequential.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Test.StateMachine.Sequential
, ShouldShrink(..)
, initValidateEnv
, runCommands
, runCommands'
, getChanContents
, Check(..)
, executeCommands
Expand Down Expand Up @@ -325,9 +326,16 @@ runCommands :: (Show (cmd Concrete), Show (resp Concrete))
=> StateMachine model cmd m resp
-> Commands cmd resp
-> PropertyM m (History cmd resp, model Concrete, Reason)
runCommands sm@StateMachine { initModel, cleanup } = run . go
where
go cmds = mask $ \restore -> do
runCommands sm cmds = run $ runCommands' sm cmds

runCommands' :: (Show (cmd Concrete), Show (resp Concrete))
=> (Rank2.Traversable cmd, Rank2.Foldable resp)
=> (MonadMask m, MonadIO m)
=> StateMachine model cmd m resp
-> Commands cmd resp
-> m (History cmd resp, model Concrete, Reason)
runCommands' sm@StateMachine { initModel, cleanup } cmds =
mask $ \restore -> do
hchan <- restore newTChanIO
(reason, (_, _, _, model)) <- restore
(runStateT
Expand Down