Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Turn callbacks, arrays, generators, generator functions, and promises into a thunk
The 'thunkify' npm package is used to convert functions that take a callback into functions that return thunks. Thunks are functions that encapsulate a computation or action to be performed later, which can be particularly useful in asynchronous programming.
Convert callback-based functions to thunks
This feature allows you to convert a function that uses a callback (like 'fs.readFile') into a function that returns a thunk. The thunk can then be called with a callback to execute the original function.
const thunkify = require('thunkify');
const fs = require('fs');
const readFileThunk = thunkify(fs.readFile);
const thunk = readFileThunk('example.txt', 'utf8');
thunk((err, data) => {
if (err) throw err;
console.log(data);
});
The 'co' package is a generator-based control flow goodness for nodejs and the browser, using thunks. It allows you to write non-blocking code in a synchronous style using generators. Compared to 'thunkify', 'co' provides a more comprehensive solution for managing asynchronous control flow.
The 'bluebird' package is a fully featured promise library with focus on innovative features and performance. It provides a 'promisify' method that converts callback-based functions to return promises, which can be seen as an alternative to thunks. 'bluebird' offers more features and flexibility compared to 'thunkify'.
The 'util.promisify' method in Node.js standard library converts callback-based functions to return promises. It is similar to 'thunkify' in that it transforms callback-based functions, but it uses promises instead of thunks. This is a built-in utility in Node.js and is widely used for modern asynchronous programming.
Turn a regular node function into one which returns a thunk, useful for generator-based flow control such as co.
$ npm install thunkify
var thunkify = require('thunkify');
var fs = require('fs');
var read = thunkify(fs.readFile);
read('package.json', 'utf8')(function(err, str){
});
MIT
FAQs
Turn callbacks, arrays, generators, generator functions, and promises into a thunk
We found that thunkify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.