As background, I have an async function that does some logic, and eventually (if the browser supports it) returns a Proxy object. This is to support older legacy code that expected an object which can have many different available functions, depending on the name of the controller requested. The controller can have many different functions on it, it depends on the API functions that are available on the controller, so we just allow any function name. For example a controller can have a "controller.xyz()" or "controller.test()" or even "controller.then()".
let x = 0;
function getController() {
return new Proxy({}, {get: () => () => `test${x}`});
}
async function getControllerAsync() {
return getController();
}
function test(controller) {
console.log(controller.x());
}
test(getController());
getControllerAsync().then(test);
// Expected: test0 and test1 should output to console
// Actual: only test0 is output, the getControllerAsync() promise never resolves
The problem, though (I think), is that the async function (or a Promise resolve function) thinks the Proxy object is a "thenable" object, or at least I think so. I don't understand, though, if that were the case why would the the Promise not resolve to a string instead of never resolving?