async2sync2
v0.0.2
Published
A tool that converts asynchronous functions into synchronous functions. It achieves synchronous execution of asynchronous functions by extracting the function source code into a separate JavaScript file and running it.
Readme
async2sync2
Project Introduction
async2sync2 is a tool that converts asynchronous functions into synchronous functions. It achieves synchronous execution of asynchronous functions by extracting the function source code into a separate JavaScript file and running it.
Installation
npm install async2sync2Usage
const { async2sync2 } = require('async2sync2');
const asyncFn = async (a, b) => {
return a + b;
};
const result = async2sync2(asyncFn)(1, 2);
console.log(result); // Output: 3Configuration Options
tempDir: Temporary file storage directoryclearTemp: Whether to clear temporary files, default istruereturnDetail: Whether to return detailed information, default isfalsecb: Error callback function
Here is an example using all configuration options:
const asyncFn = async (a, b) => {
return a + b
}
const { res } = async2sync2(asyncFn, {
returnDetail: true,
})(1, 2)
expect(res).toStrictEqual(3)Running Tests
npm testLicense
MIT
