Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Callback pattern, decomposition
- const getSendResultsHandler = (cb) => (err, result) => {
- if (err) {
- console.error(`Failed to send results to mothership.`);
- cb(err);
- } else {
- console.log(`Message from the mothership: ${result}`);
- cb();
- }
- };
- const getGatherResultsHandler = (cb) => (err, result) => {
- const sendResultsHandler = getSendResultsHandler(cb);
- if (err) {
- console.error(`Failed to get results, cancelling message.`);
- cb(err);
- } else {
- asyncDoSomethingWithResult(result, sendResultsHandler)
- }
- };
- function reportToMotherShipCb(callback: GenericAsyncCallback<Error, never>) {
- const gatherResultsHandler = getGatherResultsHandler(callback);
- asyncApi(gatherResultsHandler);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement