Run IO operations asynchronously and wait for their results

Version on this page:2.2.3
LTS Haskell 22.30:2.2.5@rev:1
Stackage Nightly 2024-07-22:2.2.5@rev:1
Latest on Hackage:2.2.5@rev:1

See all snapshots async appears in

BSD-3-Clause licensed by Simon Marlow
Maintained by Simon Marlow
This version can be pinned in stack with:async-2.2.3@sha256:0cbefb8247308b38e397e675f832b9bd5317ff1872001d5358f213654423c55b,2920

Module documentation for 2.2.3

This package provides a higher-level interface over threads, in which an Async a is a concurrent thread that will eventually deliver a value of type a. The package provides ways to create Async computations, wait for their results, and cancel them.

Using Async is safer than using threads in two ways:

  • When waiting for a thread to return a result, if the thread dies with an exception then the caller must either re-throw the exception (wait) or handle it (waitCatch); the exception cannot be ignored.

  • The API makes it possible to build a tree of threads that are automatically killed when their parent dies (see withAsync).


Changes in 2.2.3:

  • Documentation fixes

Changes in 2.2.2:

  • Builds with GHC 8.6.x
  • linkOnly and link2Only are now exported
  • wait now has the same behaviour with BlockedIndefinitelyOnSTM as waitCatch
  • Documentation fixes

Changes in 2.2.1:

  • Add a Hashable instance for Async
  • Bump upper bounds
  • Documentation updates

Changes in 2.2:

  • cancel now throws AsyncCancelled instead of ThreadKilled
  • link and link2 now wrap exceptions in ExceptionInLinkedThread when throwing to the linked thread. ExceptionInLinkedThread is a child of AsyncException in the exception hierarchy, so this maintains the invariant that exceptions thrown asynchronously should be AsyncExceptions.
  • link and link2 do not propagate AsyncCancelled, so it’s now possible to cancel a linked thread without cancelling yourself.
  • Added linkOnly and link2Only to specify which exceptions should be propagated,if you want something other than the default behaviour of ignoring AsyncCancelled.
  • new utility function compareAsyncs for comparing Asyncs of different types.
  • Add a Hashable instance for Async a

Changes in

  • Make ‘cancelWith’ wait for the cancelled thread to terminate, like ‘cancel’
  • Updates to dependency bounds for GHC 8.2

Changes in 2.1.1:

  • Add concurrently_
  • Add replicateConcurrently
  • Add replicateConcurrently_
  • Fix incorrect argument order in forConcurrently_
  • Generalize mapConcurrently_ and forConcurrently_ to Foldable
  • withAsync now reliably kills the thread, by using an uninterruptible cancel
  • Make cancel wait for the thread to finish, and adjust ‘concurrently’ to match

Changes in 2.1.0:

  • Bump base dependency to allow 4.10
  • Remove invalid Monad instance for Concurrently
  • Add Monoid and Semigroup instances for Concurrently
  • Add forConcurrently (flipped version of mapConcurrently)
  • Add STM version of all applicable IO functions: waitAnySTM, waitAnyCatchSTM, waitEitherSTM, waitEitherCatchSTM, waitEitherSTM_, and waitBothSTM.

Changes in 2.0.2:

  • Add a Monad instance for Concurrently
  • Bump base dependency to allow 4.9

Changes in

  • Add workaround to waitCatch for #14

Changes in

  • Bump base dependencies for GHC 7.8

Changes in

  • Bump base dependency of test suite

Changes in

  • Bump base dependency to allow 4.6

Changes in

  • Bump stm dependency to 2.4

Changes in

  • Safe Haskell support: Control.Concurrent.Async is now Trustworthy

Changes in

  • Added a Functor instance for Async
  • Added asyncBound, asyncOn, asyncWithUnmask, asyncOnWithUnmask, withAsyncBound, withAsyncOn, withAsyncWithUnmask, withAsyncOnWithUnmask.
  • Added mapConcurrently
  • Added Concurrently (with Applicative and Alternative instances)