extensible-effects-concurrent: Message passing concurrency as extensible-effect

[ bsd3, concurrency, control, effect, library, program ] [ Propose Tags ]

Modules

[Last Documentation]

  • Control
    • Eff
      • Control.Eff.Concurrent
        • Control.Eff.Concurrent.Api
          • Control.Eff.Concurrent.Api.Client
          • Control.Eff.Concurrent.Api.Observer
            • Control.Eff.Concurrent.Api.Observer.Queue
          • Control.Eff.Concurrent.Api.Server
        • Control.Eff.Concurrent.Process
          • Control.Eff.Concurrent.Process.ForkIOScheduler
          • Control.Eff.Concurrent.Process.Interactive
          • Control.Eff.Concurrent.Process.SingleThreadedScheduler
      • Control.Eff.ExceptionExtra
      • Control.Eff.Log
        • Control.Eff.Log.Channel
        • Control.Eff.Log.Handler
        • Control.Eff.Log.Message
      • Control.Eff.Loop

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.1.0, 0.1.2.0, 0.1.2.1, 0.1.2.2, 0.1.3.0, 0.2.0.2, 0.2.0.3, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.4.0.0, 0.5.0.0, 0.5.0.1, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8, 0.9.0, 0.9.2, 0.9.2.1, 0.9.2.2, 0.10.0, 0.11.1, 0.12.0, 0.12.1, 0.13.0, 0.13.2, 0.14.0, 0.14.1, 0.14.2, 0.14.3, 0.15.0, 0.16.0, 0.16.1, 0.17.0, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.20.0, 0.21.0, 0.21.1, 0.22.0, 0.22.1, 0.23.0, 0.24.0, 0.24.1, 0.24.2, 0.24.3, 0.25.0, 0.25.1, 0.26.0, 0.26.1, 0.27.0, 0.28.0, 0.29.0, 0.29.1, 0.29.2, 0.30.0, 0.31.0, 0.32.0, 2.0.0
Change log ChangeLog.md
Dependencies async (>=2.2 && <3), base (>=4.7 && <4.12), containers (>=0.5.8 && <0.7), data-default, deepseq, directory, enclosed-exceptions (>=1.0 && <1.1), extensible-effects (>=3.1 && <4), extensible-effects-concurrent, filepath, lens, monad-control, mtl, parallel, process, QuickCheck (<2.12), stm (>=2.4.5 && <2.6), time [details]
License BSD-3-Clause
Copyright Copyright Sven Heyll
Author Sven Heyll
Maintainer sven.heyll@gmail.com
Category Concurrency
Home page https://github.com/sheyll/extensible-effects-concurrent#readme
Bug tracker https://github.com/sheyll/extensible-effects-concurrent/issues
Source repo head: git clone https://github.com/sheyll/extensible-effects-concurrent
Uploaded by SvenHeyll at 2018-11-05T11:03:17Z
Distributions
Executables extensible-effects-concurrent-example-4, extensible-effects-concurrent-example-3, extensible-effects-concurrent-example-2, extensible-effects-concurrent-example-1
Downloads 29355 total (219 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2018-11-05 [all 3 reports]

Readme for extensible-effects-concurrent-0.9.2

[back to package description]

extensible-effects-concurrent

Message passing concurrency with 'forkIO' and 'extensible-effects' inspired by Erlang.

Build Status

Hackage

Also included:

  • Logging

  • Memory Leak Free forever

Example

module Main where

import           Control.Eff
import           Control.Eff.Lift
import           Control.Eff.Concurrent
import           Data.Dynamic
import           Control.Concurrent
import           Control.DeepSeq

main :: IO ()
main = defaultMain
  (do
    lift (threadDelay 100000) -- because of async logging
    firstExample forkIoScheduler
    lift (threadDelay 100000) -- ... async logging
  )
    -- The SchedulerProxy paremeter contains the effects of a specific scheduler
    -- implementation.

newtype WhoAreYou = WhoAreYou ProcessId deriving (Typeable, NFData)

firstExample :: (HasLoggingIO q) => SchedulerProxy q -> Eff (Process q ': q) ()
firstExample px = do
  person <- spawn
    (do
      logInfo "I am waiting for someone to ask me..."
      WhoAreYou replyPid <- receiveMessageAs px
      sendMessageAs px replyPid "Alice"
      logInfo (show replyPid ++ " just needed to know it.")
    )
  me <- self px
  sendMessageAs px person (WhoAreYou me)
  personName <- receiveMessageAs px
  logInfo ("I just met " ++ personName)

Running this example causes this output: (not entirely true because of async logging, but true enough)

2018-11-05T10:50:42 DEBUG     scheduler loop entered                                                   ForkIOScheduler.hs line 131
2018-11-05T10:50:42 DEBUG            !1 [ThreadId 11] enter process                                                            ForkIOScheduler.hs line 437
2018-11-05T10:50:42 NOTICE           !1 [ThreadId 11] ++++++++ main process started ++++++++                                   ForkIOScheduler.hs line 394
2018-11-05T10:50:42 DEBUG            !2 [ThreadId 12] enter process                                                            ForkIOScheduler.hs line 437
2018-11-05T10:50:42 INFO             !2 [ThreadId 12] I am waiting for someone to ask me...                                               Main.hs line 27
2018-11-05T10:50:42 INFO             !2 [ThreadId 12] !1 just needed to know it.                                                          Main.hs line 30
2018-11-05T10:50:42 DEBUG            !2 [ThreadId 12] returned                                                                 ForkIOScheduler.hs line 440
2018-11-05T10:50:42 INFO             !1 [ThreadId 11] I just met Alice                                                                    Main.hs line 35
2018-11-05T10:50:42 NOTICE           !1 [ThreadId 11] ++++++++ main process returned ++++++++                                  ForkIOScheduler.hs line 396
2018-11-05T10:50:42 DEBUG            !1 [ThreadId 11] returned                                                                 ForkIOScheduler.hs line 440
2018-11-05T10:50:42 DEBUG     scheduler loop returned                                                  ForkIOScheduler.hs line 133
2018-11-05T10:50:42 DEBUG     scheduler cleanup begin                                                  ForkIOScheduler.hs line 137
2018-11-05T10:50:42 NOTICE    cancelling processes: []                                                 ForkIOScheduler.hs line 149
2018-11-05T10:50:42 DEBUG     scheduler cleanup done                                                   ForkIOScheduler.hs line 141

TODO

Stackage

Still todo...

extensible-effects-concurrent LTS

Scheduler Variation

The ambiguity-flexibility trade-off introduced by using extensible effects kicks in because the Process type has a Spawn clause, which needs to know the Effects.

That is resolved by an omnipresent scheduler proxy parameter.

I will resolve this issue in one of these ways, but haven't decided:

  • By using backpack - best option, apart from missing stack support

  • By duplicating the code for each scheduler implementation

  • By using implicit parameters (experimental use of that technique is in the logging part) - problem is that implicit parameter sometimes act weired and also might break compiler inlineing.

Other

  • Process Linking/Monitoring

  • Scheduler ekg Monitoring

  • Timers and Timeouts (e.g. in receive)

  • Rename stuff