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

@ghost

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!

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