talira

Run IO operations asynchronously and wait for their results

open sourceBSD-3-Clausefree

async is a Haskell library that gives a higher-level interface over threads: an Async is a concurrent thread that will eventually deliver a value, and the library has ways to create these computations, wait for their results and cancel them. It is safer than raw threads because an exception in a thread can't be silently ignored by the caller, and withAsync builds a tree of threads that are killed automatically when their parent dies. It also has combinators such as concurrently, race and mapConcurrently, and since 2.2.6 bounded stream processing.

Problems it solves

  • run several IO actions at the same time in Haskell and wait for all their results
  • make sure an exception in a background thread reaches the code waiting for it instead of being lost
  • race two IO actions in Haskell and cancel the one that loses

Features

  • Async values for threads that return a result
  • wait, waitCatch and cancel with exceptions re-thrown to the caller
  • withAsync kills child threads when the parent finishes
  • concurrently, race and mapConcurrently combinators
  • mapConcurrentlyBounded and Control.Concurrent.Stream for a fixed number of workers
  • Warden for Asyncs that outlive a scope but are cancelled when orphaned

Alternatives

The same job

These do what async does.

  1. lifted-async Run lifted IO operations asynchronously in Haskell

Compare async with the top 3