Execute callback after multiple asynchronous operations
This feature allows you to specify a callback function that will be executed after a certain number of asynchronous operations have completed. In this example, the callback will be executed after three tasks have finished.
const after = require('after');
const done = after(3, () => {
console.log('All tasks completed');
});
setTimeout(() => {
console.log('Task 1 done');
done();
}, 1000);
setTimeout(() => {
console.log('Task 2 done');
done();
}, 2000);
setTimeout(() => {
console.log('Task 3 done');
done();
}, 3000);