Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

waitUntilReady never settles #78

Closed

Description

@johnvh

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.

Activity

  1. apucacao commented on Feb 13, 2018

    @apucacao
    Contributor

    Thanks for reporting this @johnvh . FYI, this is on our list to fix shortly.

  2. dylanjha commented on May 1, 2018

    @dylanjha
    Contributor

    This had me confused too

  3. dylanjha commented on May 3, 2018

    @dylanjha
    Contributor

    This should resolve the issue #89

    @johnvh and anyone else mind giving this a try? You should be able to try it out by updating package.json like so:

    "ldclient-node": "git://github.com/dylanjha/node-client#dj/wait-until-ready-resolve"

    (IMPORTANT: The above recommendation is for testing out the change only, don't check that into source control, it's safer to wait until the change gets merged so you can update the ldclient-node to an official version)

  4. apucacao commented on May 3, 2018

    @apucacao
    Contributor

    We just published 4.0.5 which includes your contribution @dylanjha — thank you :)

    /cc @johnvh

  5. dylanjha commented on May 3, 2018

    @dylanjha
    Contributor

    @apucacao so quick! Thank you 🙏

  6. added a commit that references this issue on May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions