You cannot know that. You have to wrap the thing in try..finally
to protect yourself from bugs/exceptions it doesn't handle:
async function doLongRunningTask() {
const connection = await getConnectionFromPool()
let res;
try {
res = await connection.fetchResource()
} finally {
connection.release()
}
const { error, resource } = res;
...
No, but they must deal gracefully with exceptions at every function call or await
or yield
expression (those latter two are natural cancellation points, because they are allowed to never return in current ES). Cancellation is a request, not a command (ever tried Ctrl-C
on a program that's not cooperating? :D). It's not the same thing as "force-stopping" a running function at any point, which obviously is a no-go.