Two promises with a single then for either one of them

Tags: ,

I have a function that takes an input, according to that input it will either call one of two functions (both return a promise) I want then to call the same .then() after whatever of them happened.

I found Promise.any() but that doesn’t quite do what I want.

For curious minds :

I am working on a react-native app and want to either open the camera or the gallery then handle the photo in a then().

How can I do that?


function myFunction(input) {
  const promise = input === X ? callOne() : callTwo();
  return promise.then(handleEitherFunction);

Source: stackoverflow