offload long running function in javascript/node

I’d like to await a function, call it

runThirdPartyCall()

however, I don’t know how long this will take ahead of time. If it takes longer than 30 seconds, i’d like to return from the request early, but still be able to reason about what runThirdPartyCall() returns.

Is this possible to do with workers? I see that javascript cannot directly hand over the execution of a function or the promise it returns to another thread or process once it has started, so i’m wondering if there are any alternatives.

I’m stuck wondering about the general problem, when you have a third party call of which you don’t know how long it will take, and if it ends up taking too long you want to go and inform the client/move on to other things