Consider the following snippet:
try {
const client = getClientThatMustBeClosed();
const data = await shortRunningOperation(client);
return Promise.resolve(data);
} catch (error) {
return Promise.reject(error);
} finally {
// any exception in the following function is caught and dealt with internally...
await longRunningOperation(client);
client.close();
}
Ideally I want to return data to the calling function right after shortRunningOperation() completes, without waiting for longRunningOperation() to complete. But closing the client must wait until after longRunningOperation() completes.
This jsfiddle would suggest that the return statement waits for the finally block to complete... in which case, what is the correct way to get data back to the calling function ASAP without waiting for longRunningOperation() to complete?