conio: 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]

conio 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), containers (>=0.7 && <0.8), stm (>=2.5.3 && <2.6), transformers (>=0.6.1 && <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/conio
Uploaded by voyager at 2025-06-07T16:05:11Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for conio-0.0.0.1

[back to package description]

ConIO

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 implements 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

example1 :: IO ()
example1 =
  -- open up a concurrency scope
  runConIO $ do
    -- launch tasks
    task1 <- launch action1
    task2 <- launch action2
    pure ()
  -- waits until `action1` and `action2` are done
example2 :: IO ()
example2 =
  -- open up a concurrency scope
  runConIO $ do
    -- launch task
    task <- launch $ pure 10
    
    -- do some work
    let x = 10

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

    -- prints 20
    print $ x + result
example3 :: IO ()
example3 =
  -- open up a concurrency scope
  runConIO $ do
    -- launch task
    task <- launch $ threadDelay 10000000

    -- cancel task
    cancel task
example4 :: IO ()
example4 =
  -- open up a concurrency scope
  runConIO $ do
    -- launch task
    task <- raceTwo (threadDelay 1000000 >> pure 10) (pure 20)

    -- wait for result and cancel the slower thread
    result <- wait task

    -- prints 20
    print result

Comparison with other libraries

Acknowledgements