You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 30, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on May 30, 2024. It is now read-only.
use .waitForInitialzation().then(...) instead of .once('ready',...) #110
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
ghost changed the title [-]use .waitForInitialzation instead of .once('ready',...)[/-][+]use .waitForInitialzation().then(...) instead of .once('ready',...)[/+]on Aug 17, 2018
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.
Activity
[-]use .waitForInitialzation instead of .once('ready',...)[/-][+]use .waitForInitialzation().then(...) instead of .once('ready',...)[/+]eli-darkly commentedon Aug 17, 2018
The intention was not to wait for the
readyevent during every request, but just at startup time. By definition, usingonceto listen for an event will only ever call the handler once, so it would never make sense to useoncein a request handler. We'll try to clarify the documentation.Merge pull request #110 from launchdarkly/eb/fix-store-test
bwoskow-ld commentedon Apr 4, 2019
I update the documentation to clarify that the
readyevent is only emitted once, and that production code shouldn't depend on using that.