Error Handling in Async Code
What advanced error handling pattern is demonstrated?
async function transactional(operation) {
const cleanup = [];
try {
return await operation(cleanup);
} catch (error) {
for (const cleanupFn of cleanup.reverse()) {
try {
await cleanupFn();
} catch (cleanupError) {
console.error('Cleanup failed:', cleanupError);
}
}
throw error;
}
}