I am trying to return a variable which is set by a Promise's then() in a JS function.
The function is called externally by including the myScript.js file
For eg:
myScript.js
function myFunc(){
var myFieldToReturn;
functionThatReturnsPromise().then(function(data){\n
//The value of "data" is used to perform some operations and
//should be returned to the caller of myFunc()
myFieldToReturn = data + "Hi";
});
return myFieldToReturn;
}
functionThatReturnsPromise()
is a function defined external to this script and is not modifiable.
Call to myFunc
is also external and I have no control on the way my return value is used (So, I cannot send back a promise
as my function's return value).
Any help on would be appreciated.
Thank You