Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcello3d/node-taxman
Taxman caches values for you.
https://github.com/marcello3d/node-taxman
Last synced: 15 days ago
JSON representation
Taxman caches values for you.
- Host: GitHub
- URL: https://github.com/marcello3d/node-taxman
- Owner: marcello3d
- License: zlib
- Created: 2011-05-05T02:38:36.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-08-29T22:58:29.000Z (about 13 years ago)
- Last Synced: 2024-10-19T15:18:04.755Z (28 days ago)
- Language: JavaScript
- Homepage: https://github.com/marcello3d/node-taxman
- Size: 93.8 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
node-taxman
===========
Taxman caches values for you.Introduction
------------
This module was inspired by the need for an easy way to asynchronously compute a value once, but use it in multiple
places.Examples
--------
var taxman = require('taxman')
// Create a taxman to compute the value
var computation = taxman(function(callback) {
console.log("Doing lots of hard work...")
var x = 3 * 5
callback(null, x)
})// Get the computation value (this first call will start the computation, synchronously, in this case)
computation(function(error, value) {
if (error) {
console.error("1a: computation failed")
} else {
console.log("1a: success! result = ", value)
}
})// Get the computation value again (retrieves cached value)
computation(function(error, value) {
if (error) {
console.error("1b: computation failed")
} else {
console.log("1b: success! result = ", value)
}
})// Reset the cache
computation.reset()// Get the computation value (this will re-compute the value)
computation(function(error, value) {
if (error) {
console.error("1c: computation failed")
} else {
console.log("1c: success! result = ", value)
}
})Outputs:
Doing lots of hard work...
1a: success! result = 15
1b: success! result = 15
Doing lots of hard work...
1c: success! result = 15See [test.js][1] for more examples.
License
-------
Taxman is open source software under the [zlib license][2].[1]: https://github.com/marcello3d/node-taxman/blob/master/test.js
[2]: https://github.com/marcello3d/node-taxman/blob/master/LICENSE