Say I have two functions:
function f1() {
return new Promise<any>((resolve, reject) => {
resolve(true);
});
}
function f2() {
}
How do I know if f1
will return Promise
and f2
will not?
Say I have two functions:
function f1() {
return new Promise<any>((resolve, reject) => {
resolve(true);
});
}
function f2() {
}
How do I know if f1
will return Promise
and f2
will not?
Call the function, use
instanceof
This can't be done.
You can, however, cast any function to a Promise-returning function. This is what I'd do here.
So it's just about normalizing the output. Then run it through
Promise.resolve()
and co.or
But you need to have a basic Idea of what these functions return. For Example: Both examples would fail with
You need to know that
f3
returns an Array of Promises or values and deal with it. Like you need to know thatf1
andf2
return a value or a Promise of a value.Bottom line: you need to have a basic knowledge of what a function returns to be able to run the result through the proper function to resolve the promises.