Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const onGatherResultsError = e => {
- console.error('Failed to get results, cancelling message.')
- throw e;
- }
- const onSendResultsError = e => {
- console.error('Failed to send results to the mothership')
- throw e;
- }
- const getMessage = (result : number) => pAsyncDoSomethingWithResult(result).catch(onSendResultsError);
- function reportToMotherShipPromise() {
- console.log(`Sending results to the mother ship...`);
- return pAsyncApi()
- .catch(onGatherResultsError)
- .then(getMessage)
- .then((message) => console.log(`Message from the mothership: ${message}`));
- }
- async function reportToMotherShipAsync() {
- console.log(`Sending results to the mothership...`);
- const result = await pAsyncApi().catch(onGatherResultsError);
- const message = await pAsyncDoSomethingWithResult(result).catch(onSendResultsError);
- console.log(`Message from the mothership : ${message}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement