multitasking: A structured concurrency library

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

multitasking aims to simplify concurrency in Haskell, providing an easy way to spawn threads with sane defaults. It uses structured concurrency to control the lifetime of threads.


[Skip to Readme]

Properties

Versions 0.0.0.1
Change log None available
Dependencies base (>=4.20.0.0 && <4.21), ki (>=1.0 && <1.1), stm (>=2.5.3 && <2.6), transformers (>=0.6 && <0.7) [details]
License BSD-3-Clause
Copyright Simon Reitinger
Author Simon Reitinger
Maintainer simre4775@gmail.com
Category Concurrency
Source repo head: git clone https://github.com/Simre1/multitasking
Uploaded by voyager at 2025-07-03T15:58:49Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for multitasking-0.0.0.1

[back to package description]

Multitasking

Haskell has great tools for dealing with concurrency. However, in praxis they are difficult to use.

This library aims to make concurrency easy by providing many built-in solutions for common concurrency patterns. It is based on structured concurrency, not letting threads outlive their parent scope. Additionally, exceptions are propagated automatically. This means that you do not have to worry about:

Examples

awaitAllExample :: IO ()
awaitAllExample =
  -- open up a concurrency scope
  multitask $ \coordinator -> do
    -- launch tasks
    task1 <- start coordinator action1
    task2 <- start coordinator action2
    -- Wait for all actions to complete
    await coordinator
awaitTaskExample :: IO ()
awaitTaskExample =
  -- open up a concurrency scope
  multitask $ \coordinator -> do
    -- start task
    task <- start coordinator $ pure 10
    
    -- do some work
    let x = 10

    -- wait for task to complete and get the result
    result <- await task

    -- prints 20
    print $ x + result
raceTasksExample :: IO ()
raceTasksExample = multitask $ \coordinator ->
  slot <- newSlot
  _ <- start coordinator $ action1 >>= putSlot slot
  _ <- start coordinator $ action2 >>= putSlot slot
  result <- awaitSlot slot
  print result
builtinRaceExample :: IO ()
builtinRaceExample = do
    result <- raceTwo (threadDelay 1000000 >> pure 10) (pure 20)
    print result

Comparison with other libraries

Acknowledgements