Hmm, this question is How to Proxy a Promise. I arrived here looking for How to Promise a Proxy -- or maybe more precisely, How to resolve a Proxy. I suspect others may land here, too, so I'll post this here, just in case.
I already have a nice working proxy object, and then I go and try to wrap it in a promise:
var p = new Promise(function(resolve, reject) {
var proxy = get_my_proxy();
resolve(proxy);
});
And wouldn't you know it, then darn resolve method asks my proxy for a then
property (which is unexpected by my proxy logic, causing it to throw). It may not be ideal, depending on what your proxy is for, but here's how I worked around this (and appropriately enough, as my question is the inverse of this one, my solution is the inverse as well) -- by returning null
for then
-- thereby letting resolve()
know that I didn't pass it a Promise
(aka Thenable
).
get: function(target, prop) {
if (prop === 'then') return null; // I'm not a Thenable
// ...the rest of my logic
}