The types of the function arguments
The type of the value that the Promise resolves to (default: unknown)
The type of the error that might be caught (default: any)
A function that returns a Promise
A function that accepts a Node-style callback as its first argument
// Using with Store event handlers (which expect synchronous functions)
// Instead of this (which uses async in a non-async context):
myStore.on('update', async (event) => {
const data = await fetchDataFromApi(event.value);
// Do something with data...
});
// Do this instead:
const handleUpdateAsync = async (event) => {
const data = await fetchDataFromApi(event.value);
// Do something with data...
};
myStore.on('update', (event) => {
callbackify(handleUpdateAsync)(
(err, _) => { if (err) console.error('Error:', err); },
event
);
});
Converts a function that returns a Promise into a function that accepts a Node-style callback.
This utility helps integrate Promise-based code with callback-based APIs, including using async operations in synchronous contexts like Store event handlers.