thunky
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Thunky is a JavaScript library that delays the evaluation of a parameter-less asynchronous function and caches the result. This method is inspired by the concept of 'thunk' in functional programming. This package can be especially useful when implementing lazy evaluation patterns in your application.
To start using Thunky, first install it via npm with the command npm install thunky
. Here's an example showcasing how Thunky can be used in your project:
var thunky = require('thunky')
var test = thunky(function (callback) {
console.log('waiting 1s and returning random number')
setTimeout(function () {
callback(Math.random())
}, 1000)
})
test(function (num) {
console.log(num)
})
test(function (num) {
console.log(num)
})
In this example, the test
function, when called for the first time, waits for 1 second and then returns a random number. Subsequent calls to the function will return the same random number as the first call, effectively showcasing Thunky's caching capability.
The Thunky documentation can be found on the package's GitHub repository at git://github.com/mafintosh/thunky.git. Here, you'll find everything from the package's introduction and installation to several usage examples and notes on its functionality. Remember, understanding how Thunky, or any package for that matter, works is crucial for its effective implementation in your projects.