polysemy-conc 0.14.1.1 → 0.15.0.0
raw patch · 7 files changed
+70/−53 lines, 7 filesdep ~basedep ~hedgehogdep ~incipit-core
Dependency ranges changed: base, hedgehog, incipit-core, polysemy-conc, polysemy-resume, polysemy-test, tasty, tasty-hedgehog, time
Files
- lib/Polysemy/Conc.hs +5/−7
- lib/Polysemy/Conc/Effect/Mask.hs +17/−10
- lib/Polysemy/Conc/Interpreter/Mask.hs +24/−10
- lib/Polysemy/Conc/Interpreter/Stack.hs +4/−6
- polysemy-conc.cabal +17/−17
- test/Main.hs +1/−1
- test/Polysemy/Conc/Test/MaskTest.hs +2/−2
lib/Polysemy/Conc.hs view
@@ -115,6 +115,7 @@ -- * Masking Mask,+ MaskMode (..), UninterruptibleMask, mask, uninterruptibleMask,@@ -188,7 +189,7 @@ import Polysemy.Conc.Effect.Events (Consume, Events, consume, publish, subscribe) import Polysemy.Conc.Effect.Gate (Gate, Gates) import Polysemy.Conc.Effect.Lock (Lock, lock, lockOr, lockOrSkip, lockOrSkip_)-import Polysemy.Conc.Effect.Mask (Mask, Restoration, UninterruptibleMask, mask, restore, uninterruptibleMask)+import Polysemy.Conc.Effect.Mask (Mask, MaskMode (..), Restoration, UninterruptibleMask, mask, restore, uninterruptibleMask) import Polysemy.Conc.Effect.Monitor (Monitor, Restart, RestartingMonitor, ScopedMonitor, monitor, restart, withMonitor) import Polysemy.Conc.Effect.Queue (Queue) import Polysemy.Conc.Effect.Race (Race, race, timeout)@@ -275,10 +276,9 @@ -- $mask -- #mask#--- The two effects 'Mask' and 'UninterruptibleMask' use the 'Polysemy.Scoped' pattern, which allow an effect--- with resources to be constrained to a region of code.--- The actual effect is 'Polysemy.Conc.Effect.Mask.RestoreMask', with `mask` and 'uninterruptibleMask' only specializing--- 'Polysemy.Conc.Effect.scoped' to the appropriate resource type.+-- The 'Mask' effect uses the 'Polysemy.Scoped' pattern with 'MaskMode' as the scope parameter.+-- 'mask' and 'uninterruptibleMask' are convenience functions that pass 'Interruptible' or 'Uninterruptible' to+-- 'Polysemy.scoped'. -- -- Usage is straightforward: --@@ -291,5 +291,3 @@ -- doUnmaskedThing -- doMaskedThing -- @------ The @resource@ parameter stays polymorphic; it is used to connect the resource in the interpreter to the callsite.
lib/Polysemy/Conc/Effect/Mask.hs view
@@ -21,26 +21,33 @@ newtype Restoration = Restoration { unRestoration :: ∀ a . IO a -> IO a } --- | The scoped masking effect.+-- | Whether 'mask' or 'uninterruptibleMask' was requested.+data MaskMode =+ Interruptible+ |+ Uninterruptible+ deriving stock (Eq, Show)++-- | The scoped masking effect, parameterized by 'MaskMode'. type Mask =- Scoped_ RestoreMask+ Scoped MaskMode RestoreMask --- | The scoped uninterruptible masking effect.-type UninterruptibleMask =- Scoped_ RestoreMask+-- | Deprecated synonym for 'Mask'.+type UninterruptibleMask = Mask+{-# deprecated UninterruptibleMask "Use Mask instead, which now handles both variants via MaskMode" #-} -- | Mark a region as masked.--- Uses the 'Scoped_' pattern.+-- Uses the 'Scoped' pattern with 'Interruptible'. mask :: Member Mask r => InterpreterFor RestoreMask r mask =- scoped_+ scoped Interruptible -- | Mark a region as uninterruptibly masked.--- Uses the 'Scoped_' pattern.+-- Uses the 'Scoped' pattern with 'Uninterruptible'. uninterruptibleMask ::- Member UninterruptibleMask r =>+ Member Mask r => InterpreterFor RestoreMask r uninterruptibleMask =- scoped_+ scoped Uninterruptible
lib/Polysemy/Conc/Interpreter/Mask.hs view
@@ -8,9 +8,9 @@ import Polysemy.Conc.Effect.Mask ( Mask,+ MaskMode (Interruptible, Uninterruptible), Restoration (Restoration), RestoreMask (Restore),- UninterruptibleMask, ) mask ::@@ -39,28 +39,42 @@ Restore ma -> withStrategicToFinal (restore <$> runS (runTSimple ma)) +maskForMode ::+ Member (Final IO) r =>+ MaskMode ->+ (Restoration -> Sem r a) ->+ Sem r a+maskForMode = \case+ Interruptible -> mask+ Uninterruptible -> uninterruptibleMask+ -- | Interpret 'Mask' by sequencing the action without masking. interpretMaskPure :: InterpreterFor Mask r interpretMaskPure = interpretScopedH (const ($ ())) \ () -> \case Restore ma -> runTSimple ma --- | Interpret 'Mask' in 'IO'.+-- | Interpret 'Mask' in 'IO', dispatching on 'MaskMode' to select 'Base.mask' or 'Base.uninterruptibleMask'. interpretMaskFinal :: Member (Final IO) r => InterpreterFor Mask r interpretMaskFinal =- runScoped (const mask) \ r -> interpretRestoreMask r+ runScoped maskForMode interpretRestoreMask --- | Interpret 'UninterruptibleMask' by sequencing the action without masking.-interpretUninterruptibleMaskPure :: InterpreterFor UninterruptibleMask r+-- | Interpret 'Mask' by sequencing the action without masking.+--+-- @since 0.14.1.0+{-# deprecated interpretUninterruptibleMaskPure "Use interpretMaskPure, which now handles both variants" #-}+interpretUninterruptibleMaskPure :: InterpreterFor Mask r interpretUninterruptibleMaskPure =- interpretScopedH (const ($ ())) \ () -> \case- Restore ma -> runTSimple ma+ interpretMaskPure --- | Interpret 'UninterruptibleMask' in 'IO'.+-- | Interpret 'Mask' in 'IO'.+--+-- @since 0.14.1.0+{-# deprecated interpretUninterruptibleMaskFinal "Use interpretMaskFinal, which now handles both variants" #-} interpretUninterruptibleMaskFinal :: Member (Final IO) r =>- InterpreterFor UninterruptibleMask r+ InterpreterFor Mask r interpretUninterruptibleMaskFinal =- runScoped (const uninterruptibleMask) \ r -> interpretRestoreMask r+ interpretMaskFinal
lib/Polysemy/Conc/Interpreter/Stack.hs view
@@ -4,16 +4,15 @@ module Polysemy.Conc.Interpreter.Stack where import Polysemy.Conc.Effect.Gate (Gates)-import Polysemy.Conc.Effect.Mask (Mask, UninterruptibleMask)+import Polysemy.Conc.Effect.Mask (Mask) import Polysemy.Conc.Effect.Race (Race) import Polysemy.Conc.Interpreter.Gate (interpretGates)-import Polysemy.Conc.Interpreter.Mask (interpretMaskFinal, interpretUninterruptibleMaskFinal)+import Polysemy.Conc.Interpreter.Mask (interpretMaskFinal) import Polysemy.Conc.Interpreter.Race (interpretRace) -- | A default basic stack with 'Final' for _polysemy-conc_. type ConcStack = [- UninterruptibleMask, Mask, Gates, Race,@@ -23,7 +22,7 @@ Final IO ] --- | Interprets 'UninterruptibleMask', 'Mask' and 'Race' in terms of @'Final' 'IO'@ and runs the entire rest of the+-- | Interprets 'Mask' and 'Race' in terms of @'Final' 'IO'@ and runs the entire rest of the -- stack. runConc :: Sem ConcStack a ->@@ -35,5 +34,4 @@ asyncToIOFinal . interpretRace . interpretGates .- interpretMaskFinal .- interpretUninterruptibleMaskFinal+ interpretMaskFinal
polysemy-conc.cabal view
@@ -1,11 +1,11 @@ cabal-version: 2.2 --- This file has been generated from package.yaml by hpack version 0.36.1.+-- This file has been generated from package.yaml by hpack version 0.38.2. -- -- see: https://github.com/sol/hpack name: polysemy-conc-version: 0.14.1.1+version: 0.15.0.0 synopsis: Polysemy effects for concurrency description: See https://hackage.haskell.org/package/polysemy-conc/docs/Polysemy-Conc.html category: Concurrency@@ -86,8 +86,10 @@ LiberalTypeSynonyms MonadComprehensions MultiWayIf+ NoFieldSelectors OverloadedLabels OverloadedLists+ OverloadedRecordDot OverloadedStrings PackageImports PartialTypeSignatures@@ -103,15 +105,13 @@ UndecidableInstances UnicodeSyntax ViewPatterns- OverloadedRecordDot- NoFieldSelectors ghc-options: -Wall -Widentities -Wincomplete-uni-patterns -Wmissing-deriving-strategies -Wredundant-constraints -Wunused-type-patterns -Wunused-packages build-depends: async >=2.2.4 && <2.3- , base >=4.17.2.1 && <4.21- , incipit-core >=0.4.1.0 && <0.7+ , base >=4.17.2.1 && <4.22+ , incipit-core >=0.4.1.0 && <0.8 , polysemy >=1.9.0.0 && <1.10- , polysemy-resume >=0.5.0.0 && <0.10+ , polysemy-resume >=0.7.0.0 && <0.10 , polysemy-time >=0.5.1.0 && <0.8 , stm >=2.5.1.0 && <2.6 , stm-chans >=2.0.0 && <3.1@@ -153,8 +153,10 @@ LiberalTypeSynonyms MonadComprehensions MultiWayIf+ NoFieldSelectors OverloadedLabels OverloadedLists+ OverloadedRecordDot OverloadedStrings PackageImports PartialTypeSignatures@@ -170,22 +172,20 @@ UndecidableInstances UnicodeSyntax ViewPatterns- OverloadedRecordDot- NoFieldSelectors ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Widentities -Wincomplete-uni-patterns -Wmissing-deriving-strategies -Wredundant-constraints -Wunused-type-patterns -Wunused-packages build-depends: async >=2.2.4 && <2.3- , base >=4.17.2.1 && <4.21- , hedgehog >=1.1.2 && <1.6- , incipit-core >=0.4.1.0 && <0.7+ , base >=4.17.2.1 && <4.22+ , hedgehog >=1.4 && <1.8+ , incipit-core >=0.4.1.0 && <0.8 , polysemy >=1.9.0.0 && <1.10- , polysemy-conc+ , polysemy-conc <0.16 , polysemy-plugin >=0.4.4.0 && <0.5- , polysemy-test >=0.3.1.6 && <0.11+ , polysemy-test >=0.6.0.0 && <0.12 , polysemy-time >=0.5.1.0 && <0.8- , tasty >=1.4.2 && <1.6- , tasty-hedgehog >=1.3.0.0 && <1.5- , time >=1.12.2 && <1.13+ , tasty >=1.5.2 && <1.6+ , tasty-hedgehog >=1.4.0.2 && <1.5+ , time >=1.12.2 && <1.15 , torsor ==0.1.* mixins: base hiding (Prelude)
test/Main.hs view
@@ -46,7 +46,7 @@ ], testGroup "monitor" [ unitTestTimes 100 "basic" test_monitorBasic,- unitTestTimes 1000 "clock skew" test_monitorClockSkew+ unitTestTimes 100 "clock skew" test_monitorClockSkew ] ]
test/Polysemy/Conc/Test/MaskTest.hs view
@@ -13,7 +13,7 @@ import Polysemy.Conc.AtomicState (interpretAtomic) import Polysemy.Conc.Effect.Mask (restore, uninterruptibleMask) import qualified Polysemy.Conc.Effect.Sync as Sync-import Polysemy.Conc.Interpreter.Mask (interpretUninterruptibleMaskFinal)+import Polysemy.Conc.Interpreter.Mask (interpretMaskFinal) import Polysemy.Conc.Interpreter.Race (interpretRace) import Polysemy.Conc.Interpreter.Sync (interpretSync) @@ -39,7 +39,7 @@ asyncToIOFinal $ interpretRace $ interpretTimeGhc $- interpretUninterruptibleMaskFinal $+ interpretMaskFinal $ interpretAtomic (0 :: Int) $ interpretSync @(Proxy 2) $ interpretSync @(Proxy 1) do