thunky / 0.1.0 last updated 3 years ago created on Mar 6th 2013
Install
npm install --save thunky
Clone
git clone git@github.com:mafintosh/thunky.git
dependencies
No dependencies listed.
maintainers
versions
| 0.1.0 | 3 years ago | mafintosh |
readme
thunky
Delay the evaluation of a paramless async function and cache the result (see thunk).
Example
Let's make a simple function that returns a random number 1 second after it is called for the first time
Lazy evaluation
Thunky makes it easy to implement a lazy evaluation pattern.
The first time getDb is called it will try do open a connection to the database.
Any subsequent calls will just wait for the first call to complete and then call your callback.
A nice property of this pattern is that it easily allows us to pass any error caused by getDb to the queryDb callback.
Error → No caching
If the thunk callback is called with an Error object as the first argument it will not cache the result
License
MIT