lazy-async: Asynchronous actions that don't start right away

[ concurrency, library, mit ] [ Propose Tags ]

Sometimes we have a bunch of I/O actions that might not end up being needed, and we don't want to simply run all the actions upfront. We also don't want to simply run an action right before its result is needed, because it might be needed in more than one place, which opens the possibility of unnecessarily running the same action more than once. In situations like these, we use LazyAsync.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.1.0.0
Change log changelog.md
Dependencies base (>=4.14 && <4.18), exceptions (>=0.10.4 && <0.11), lifted-async (>=0.10.2 && <0.11), monad-control (>=1.0.3 && <1.1), rank2classes (>=1.4.4 && <1.5), stm (>=2.5 && <2.6), transformers (>=0.5.6 && <0.6), transformers-base (>=0.4.6 && <0.5) [details]
License MIT
Copyright 2021 Mission Valley Software LLC
Author Chris Martin
Maintainer Chris Martin, Julie Moronuki
Category Concurrency
Home page https://github.com/typeclasses/lazy-async
Bug tracker https://github.com/typeclasses/lazy-async/issues
Source repo head: git clone https://github.com/typeclasses/lazy-async
Uploaded by chris_martin at 2023-01-10T20:31:58Z
Distributions
Downloads 275 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-01-10 [all 1 reports]

Readme for lazy-async-1.0.0.2

[back to package description]

Sometimes we have a bunch of IO actions that do things like read files, make HTTP requests, or query a database. Some of the information that these actions produce might not end up being needed, depending on the breaks. In the interest of avoiding unnecessary effort, we don't want to simply run all the actions and collect their results upfront. We also don't want to simply run an action right before its result is needed, because it might be needed in more than one place, which opens the possibility of unnecessarily running the same action more than once. In situations like these, we use LazyAsync.

Under the hood, an IO action is turned into a LazyAsync by constructing two things: An Async (from the async package), and a TVar Bool (from the stm package). The TVar, initialized to False, indicates whether the action is wanted yet. The asynchronous thread waits until the TVar turns @True@ and then runs the action.