lazy-async
Version 1.0.0.0 revision 0 uploaded by chris_martin.
Package meta
- Synopsis
- Asynchronous actions that don't start right away
- 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: AnAsync
(from theasync
package), and aTVar Bool
(from thestm
package). The TVar, initialized toFalse
, indicates whether the action is wanted yet. The async thread waits until the TVar turnsTrue
and then runs the action.- Author
- Chris Martin
- Bug reports
- https://github.com/typeclasses/lazy-async/issues
- Category
- Concurrency
- Copyright
- 2021 Mission Valley Software LLC
- Homepage
- https://github.com/typeclasses/lazy-async
- Maintainer
- Chris Martin, Julie Moronuki
- Package URL
- n/a
- Stability
- n/a