-
Notifications
You must be signed in to change notification settings - Fork 64
waitUntilReady never settles #78
Description
Here are 2 cases where a promise returned by the waitUntilReady method never settles:
waitUntilReady never settles if called after ready
I would expect the following to work:
const ld = require('.');
const client = ld.init('my-key');
client.waitUntilReady()
.then(() => {
console.log('ld client ready!');
getFlag();
})
const getFlag = () => {
console.log('getFlag()');
return client.waitUntilReady()
.then(() => client.variation('some-flag', {key: 'userKey'}, false))
.then(flag => {
console.log('never gets here');
})
.catch(e => {
console.log('never gets here either');
});
};The actual behavior is that the promise returned by 2nd call to waitUntilReady never settles.
I think a better implementation would be to have waitUntilReady return a promise for a ready client (although a case can also be made that the init method should do this instead). If the client is already ready, then the promise should resolve immediately. This allows a user to chain off of it and never worry about when the client is ready. Internally, all the methods could chain off this too, making the waitUntilReady method unnecessary in the first place.
waitUntilReady does not reject on init error
I would expect the following:
const ld = require('.');
const client = ld.init('invalid key');
client.waitUntilReady()
.then(() => {
console.log('definitely dont get here');
})
.catch(error => {
console.log('very suprising that we never get here');
});... to reject with an error, since an invalid api key is an init error. The actual behavior is that the promise never settles.