After being given access to this API:
function doSomeWork(callbacks : {
success ?: (result : SuccessCallbackResult) => void,
fail ?: (result : FailCallbackResult) => void,
complete ?: (result : CompleteCallbackResult) => void
}) : Task
I managed to create a function that wraps it and returns a Promise
:
function doSomeWorkAsync() : Promise<SuccessCallbackResult> {
return new Promise((resolve, reject) => {
const callbacks = {
success: resolve,
fail: reject,
};
doSomeWork(callbacks);
});
}
However, the issue is that by doing this I lose access to the Task
returned by doSomeWork
.
Is there a way for me to modify the wrapper so that I can obtain both a Promise
and a Task
? Perhaps something along these lines:
function doSomeWorkAsync() : [Promise<SuccessCallbackResult>, Task] {
// implementation
}
Furthermore, it is crucial that the Task
is returned synchronously since it may be required to perform actions like .abort()
.