polysemy-conc 0.4.0.0 → 0.4.0.1
raw patch · 13 files changed
+42/−22 lines, 13 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- lib/Polysemy/Conc/Async.hs +3/−2
- lib/Polysemy/Conc/AtomicState.hs +1/−0
- lib/Polysemy/Conc/Effect/Events.hs +21/−7
- lib/Polysemy/Conc/Effect/Scoped.hs +4/−4
- lib/Polysemy/Conc/Effect/Sync.hs +1/−0
- lib/Polysemy/Conc/Events.hs +3/−3
- lib/Polysemy/Conc/Interpreter/Queue/TBM.hs +1/−0
- lib/Polysemy/Conc/Queue.hs +1/−0
- lib/Polysemy/Conc/Queue/Result.hs +1/−1
- lib/Polysemy/Conc/Race.hs +1/−1
- lib/Polysemy/Conc/Sync.hs +2/−1
- polysemy-conc.cabal +1/−1
- test/Polysemy/Conc/Test/EventsTest.hs +2/−2
lib/Polysemy/Conc/Async.hs view
@@ -1,3 +1,4 @@+-- |Description: Async Combinators module Polysemy.Conc.Async where import qualified Control.Concurrent.Async as Base@@ -7,9 +8,9 @@ import Polysemy.Conc.Effect.Race (Race) import qualified Polysemy.Conc.Effect.Sync as Sync-import qualified Polysemy.Conc.Race as Race+import Polysemy.Conc.Effect.Sync (ScopedSync, Sync) import Polysemy.Conc.Interpreter.Sync (interpretSync)-import Polysemy.Conc.Effect.Sync (Sync, ScopedSync)+import qualified Polysemy.Conc.Race as Race import Polysemy.Conc.Sync (withSync) -- |Run the first action asynchronously while the second action executes, then cancel the first action.
lib/Polysemy/Conc/AtomicState.hs view
@@ -1,3 +1,4 @@+-- |Description: AtomicState Interpreters module Polysemy.Conc.AtomicState where import Polysemy.AtomicState (runAtomicStateTVar)
lib/Polysemy/Conc/Effect/Events.hs view
@@ -2,14 +2,9 @@ -- |Description: Events/Consume Effects, Internal module Polysemy.Conc.Effect.Events where +import Polysemy (makeSem_) import Polysemy.Conc.Effect.Scoped (Scoped, scoped) --- |Consume events emitted by 'Events'.-data Consume (e :: Type) :: Effect where- Consume :: Consume e m e--makeSem ''Consume- -- |Marker for the 'Scoped' token for 'Events'. newtype EventToken token = EventToken { unEventToken :: token }@@ -19,7 +14,26 @@ data Events (token :: Type) (e :: Type) :: Effect where Publish :: e -> Events token e m () -makeSem ''Events+makeSem_ ''Events++-- |Publish one event.+publish ::+ ∀ e token r .+ Member (Events token e) r =>+ e ->+ Sem r ()++-- |Consume events emitted by 'Events'.+data Consume (e :: Type) :: Effect where+ Consume :: Consume e m e++makeSem_ ''Consume++-- |Consume one event emitted by 'Events'.+consume ::+ ∀ e r .+ Member (Consume e) r =>+ Sem r e -- |Create a new scope for 'Events', causing the nested program to get its own copy of the event stream. -- To be used with 'Polysemy.Conc.interpretEventsChan'.
lib/Polysemy/Conc/Effect/Scoped.hs view
@@ -9,11 +9,11 @@ -- This requires the interpreter for @effect@ to be parameterized by @resource@ and constructed for every program using -- @Scoped@ separately. ----- An application for this is 'Polysemy.Conc.Events', in which each program using the effect 'Consume' is interpreted--- with its own copy of the event channel; or a database transaction, in which a transaction handle is created for the--- wrapped program and passed to the interpreter for the database effect.+-- An application for this is 'Polysemy.Conc.Events', in which each program using the effect 'Polysemy.Conc.Consume' is+-- interpreted with its own copy of the event channel; or a database transaction, in which a transaction handle is+-- created for the wrapped program and passed to the interpreter for the database effect. ----- Resource creation is performed by the function passed to 'runScoped'.+-- Resource creation is performed by the function passed to 'Polysemy.Conc.Interpreter.runScoped'. -- -- The constructors are not intended to be used directly; the smart constructor 'scoped' is used like a local -- interpreter for @effect@.
lib/Polysemy/Conc/Effect/Sync.hs view
@@ -51,5 +51,6 @@ newtype SyncResources a = SyncResources { unSyncResources :: a } +-- |Convenience alias. type ScopedSync res a = Scoped (SyncResources res) (Sync a)
lib/Polysemy/Conc/Events.hs view
@@ -1,10 +1,10 @@ -- |Description: Events Combinators module Polysemy.Conc.Events where -import Polysemy.Conc.Interpreter.Events (EventConsumer) import qualified Polysemy.Conc.Effect.Events as Events+import Polysemy.Conc.Interpreter.Events (EventConsumer) --- |Pull repeatedly from the 'Events' channel, passing the event to the supplied callback.+-- |Pull repeatedly from the 'Polysemy.Conc.Events' channel, passing the event to the supplied callback. -- Stop when the action returns @False@. subscribeWhile :: ∀ e token r .@@ -17,7 +17,7 @@ spin = whenM (raise . action =<< Events.consume) spin --- |Pull repeatedly from the 'Events' channel, passing the event to the supplied callback.+-- |Pull repeatedly from the 'Polysemy.Conc.Events' channel, passing the event to the supplied callback. subscribeLoop :: ∀ e token r . Member (EventConsumer token e) r =>
lib/Polysemy/Conc/Interpreter/Queue/TBM.hs view
@@ -1,3 +1,4 @@+{-# options_haddock prune #-} -- |Description: Queue Interpreters for 'TBMQueue' module Polysemy.Conc.Interpreter.Queue.TBM where
lib/Polysemy/Conc/Queue.hs view
@@ -1,3 +1,4 @@+{-# options_haddock prune #-} -- |Description: Queue Combinators module Polysemy.Conc.Queue ( module Polysemy.Conc.Queue,
lib/Polysemy/Conc/Queue/Result.hs view
@@ -38,7 +38,7 @@ Just True -> QueueResult.Success () {-# inline closedBoolResult #-} --- |Turn a 'Success' into 'Just'.+-- |Turn a 'QueueResult.Success' into 'Just'. resultToMaybe :: QueueResult d -> Maybe d resultToMaybe = \case QueueResult.Success d -> Just d
lib/Polysemy/Conc/Race.hs view
@@ -65,7 +65,7 @@ timeout_ pass {-# inline timeoutU #-} --- |Variant of 'timeout' that returns 'Maybe'.+-- |Variant of 'Race.timeout' that returns 'Maybe'. timeoutMaybe :: TimeUnit u => Member Race r =>
lib/Polysemy/Conc/Sync.hs view
@@ -1,9 +1,11 @@+{-# options_haddock prune #-} -- |Description: Sync Combinators module Polysemy.Conc.Sync ( module Polysemy.Conc.Sync, module Polysemy.Conc.Effect.Sync ) where +import Polysemy.Resource (Resource, finally) import qualified Polysemy.Time as Time import Polysemy.Time (Time, TimeUnit) @@ -27,7 +29,6 @@ try, wait, )-import Polysemy.Resource (finally, Resource) -- |Run an action repeatedly until the 'Sync' variable is available. whileEmpty ::
polysemy-conc.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: polysemy-conc-version: 0.4.0.0+version: 0.4.0.1 synopsis: Polysemy Effects for Concurrency description: See <https://hackage.haskell.org/package/polysemy-conc/docs/Polysemy-Conc.html> category: Concurrency
test/Polysemy/Conc/Test/EventsTest.hs view
@@ -25,8 +25,8 @@ Sync.putBlock () Events.consume @Text Sync.takeBlock @()- Events.publish @(OutChan Text) ("test" :: Text)- Events.publish @(OutChan Int) (1 :: Int)+ Events.publish @Text @(OutChan Text) "test"+ Events.publish @Int @(OutChan Int) 1 num1 <- await thread1 num2 <- await thread2 text1 <- await thread3