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

use .waitForInitialzation().then(...) instead of .once('ready',...) #110

Closed

Description

In the docs, we are directed to create a client via const ld_client = LaunchDarkly.init('SOME_KEY');

Then in our server's request handler, we are directed to this code:

ld_client.once('ready', function() {
  ld_client.variation("your.flag.key", {"key" : "user@test.com"}, false, function(err, show_feature) {
    if (show_feature) {
        # application code to show the feature
    } else {
        # the code to run if the feature is off
    }
  });
});

However, our Node app would work the first time a request came through, but time out on the second request. Why? Because our app was waiting for the 'ready' event, and it never came. So, we went with the following, based on what we found in the source code:

 ld_client.waitForInitialization().then(() => {
   ld_client.variation("your.flag.key", {"key" : "user@test.com"}, false, function(err, show_feature) {
     if (show_feature) {
         # application code to show the feature
     } else {
         # the code to run if the feature is off
     }
   });
 }).then(console.log);

and now our node server can handle requests again, and we can update our LaunchDarkly settings and see the variations.

My only issue to please update the documentation. Thank you!

Activity

  1. ghost changed the title [-]use .waitForInitialzation instead of .once('ready',...)[/-] [+]use .waitForInitialzation().then(...) instead of .once('ready',...)[/+] on Aug 17, 2018
  2. eli-darkly commented on Aug 17, 2018

    @eli-darkly
    Contributor

    The intention was not to wait for the ready event during every request, but just at startup time. By definition, using once to listen for an event will only ever call the handler once, so it would never make sense to use once in a request handler. We'll try to clarify the documentation.

  3. added a commit that references this issue on Nov 14, 2018
  4. bwoskow-ld commented on Apr 4, 2019

    @bwoskow-ld
    Member

    I update the documentation to clarify that the ready event is only emitted once, and that production code shouldn't depend on using that.

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