When using the faye browser client with promises, I encountered an issue with a function that creates a faye client after performing an asynchronous operation:
function fayeClient() {
return doSomethingAsychronous().then(function() {
var faye_client = new Faye.Client('http://localhost/faye');
return faye_client;
});
}
I wanted to use it in the following way:
fayeClient().then(function(faye_client) {
// do something with faye_client
});
The problem is that the faye_client
itself is a thenable, causing the promise returned by fayeClient
to resolve to the value that faye_client
'resolves' to. However, I needed the promise to resolve directly to faye_client
.
Attempting to wrap the value in a promise using Promise.resolve(faye_client);
did not work, as the same promise resolution procedure was applied.
This situation made me think it might be a misuse of thenables by faye since faye_client
does not represent an unknown value.
Is there a way to create a promise that resolves to a value which is also a thenable?