Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This topic explains how to configure each SDK to allow applications to subscribe to flag change notifications. This feature is available for client-side and server-side SDKs.Subscribe to flag change notifications
Flag change notifications allow your application to react to and consider flag changes immediately instead of waiting for your code to re-evaluate a flag. Some common use cases include updating content as part of a promotion, enabling/disabling feature code paths efficiently, showing outage bulletins to end users, and granting entitlements to groups of end users. You can register multiple listeners, and they will run in parallel. Use caution if you use a flag change notification to trigger an identify call as this could lead to an infinite loop where the flag changes the context, which changes the flag, and on and on. For example, you may include additional application information if a flag is true, but you will need to make sure that the inclusion of that information does not cause the flag to toggle. Details about each SDK’s configuration are available in the SDK-specific sections below.Client-side SDKs
This feature is available in the following client-side SDKs:- .NET (client-side)
- Android
- C++ (client-side)
- Electron
- Flutter
- iOS
- JavaScript
- Node.js (client-side)
- React Native
- Roku
.NET (client-side)
Expand .NET (client-side) code sample
Expand .NET (client-side) code sample
The client uses an event pattern which allows your app to subscribe to feature flag changes in real time.To subscribe to feature flag changes, register listeners for change events from the SDK:The
FlagValueChangeEvent includes the Key, OldValue, NewValue, and Deleted properties. Since flag values can be of any type, OldValue and NewValue are represented as LdValue. Use properties like AsBool, AsString, AsInt, etc. to convert to the desired type.To learn more, read IFlagTracker.Android
Expand Android code sample
Expand Android code sample
The client uses a listener pattern which allows your app to subscribe to feature flag changes in real time.To subscribe to feature flag changes, register listeners for change events from the SDK:The flag key passed to Additionally, we provide an update listener interface for when you want to be notified when the flag cache is updated. The application provides a class implementing
onFeatureFlagChange is the key of the updated flag, which lets a single listener be registered for multiple flags.You can also disable listeners by unregistering them:These calls have been available since v2.8.0:
LDAllFlagsListenerLDClient.registerAllFlagsListenerLDClient.unregisterAllFlagsListener
LDAllFlagsListener which provides the SDK with the method onChange. Whenever the SDK’s flag cache is updated, it calls the onChange method with a list of flag keys for flags that were updated during the update to the flag cache. If no flag values changed, this list is empty.Here is an example:C++ (client-side)
Expand C++ (client-side) code sample
Expand C++ (client-side) code sample
The client exposes an interface which allows your app to subscribe to feature flag changes in real time.To subscribe to feature flag changes, register listeners for change events from the SDK:If you are working in C, there are a few more steps:To learn more, read
- Define a callback to receive the flag change notification:
- Assign the callback by creating a listener connection:
- Ensure the connection is freed when you are done with it:
FlagNotifier.Electron
Expand Electron code sample
Expand Electron code sample
The client uses an event emitter pattern which allows your app to subscribe to feature flag changes in real time.To subscribe to a specific feature flag change, register a listener for a Or, you can listen for all feature flag changes:Subscribing to
change:flag-key event from the SDK:change events automatically turns on streaming mode, unless you have explicitly set streaming to false.Flutter
Expand Flutter code sample
Expand Flutter code sample
The client uses an observer pattern which allows your app to subscribe to feature flag changes in real time.To subscribe to feature flag changes, register listeners for change events from the SDK:You can also use
flagChanges is a stream that emits all flag changes, so you can use a single listener for multiple flags.You can disable listeners by unregistering them:flagChanges if you want to be notified any time the flag cache is updated. The application provides a callback that is activated whenever the SDK receives new flag data from the service. It calls with a list of flag keys that were updated. If no flag values changed, this list is empty.To learn more, read flagChanges.iOS
Expand iOS code sample
Expand iOS code sample
The client uses an observer pattern which allows your app to subscribe to feature flag changes in real time. To subscribe to feature flag changes, register listeners for change events from the SDK.The SDK provides methods for listening to a single flag, all flags, or no change to any flag.
observeFlagsUnchanged is called when the SDK successfully receives an update or comes back online but no flags have changed. If the value of the flag changes, the method executes the handler. It passes in the changedFlag containing the old and new flag values, and old and new flag value source.The SDK retains only weak references to the owner, which lets the client app freely destroy owners without issues. Client apps should use a capture list specifying [weak self] inside handlers to avoid retain cycles causing a memory leak.The SDK executes handlers on the main thread. LDChangedFlag does not know the type of oldValue or newValue. The client app should cast the value into the type needed.To configure the client:Java
ScriptExpand JavaScript code sample
Expand JavaScript code sample
The client uses an event emitter pattern which allows your app to subscribe to feature flag changes in real time.To subscribe to all feature flag changes, register listeners for change events from the SDK:The
changedKeys array contains the keys of all flags that have changed. You can also subscribe to specific flags.Here’s how:Node.js (client-side)
Expand Node.js (client-side) code sample
Expand Node.js (client-side) code sample
The client uses an event emitter pattern which allows your app to subscribe to feature flag changes in real time.To subscribe to all feature flag changes, register listeners for change events from the SDK:The
changedKeys array contains the keys of all flags that have changed. You can also subscribe to specific flags.Here’s how:React Native
Expand React Native code sample
Expand React Native code sample
The client uses an event emitter pattern which allows your app to subscribe to feature flag changes in real time. The available event types include You can also disable listeners by unregistering them:To learn more, read
error and change.To subscribe to all feature flag changes, register listeners for change events from the SDK. Here’s how:on and off.Server-side SDKs
This feature is available in the following server-side SDKs:.NET (server-side)
Expand .NET (server-side) code sample
Expand .NET (server-side) code sample
The SDK provides an event-based mechanism to notify you when flag configurations change. To listen for changes in flag values for a specific flag key and context, use
LDClient.FlagTracker returns an interface for this mechanism, IFlagTracker.Any event handler that you add to the IFlagTracker.FlagChanged event will be called with a FlagChangeEvent whenever there is a change in any feature flag’s configuration, or in anything else that could indirectly affect the flag value, such as a prerequisite flag or a segment that the flag uses.The event data consists only of the flag key. It does not contain a flag value, because in server-side SDKs, there is no such thing as a flag value except when it is evaluated for a specific context.The listener method is called synchronously from a background task.Here’s how:IFlagTracker.FlagValueChangeHandler(). It calls your code with a FlagValueChangeEvent. This is equivalent to re-evaluating the flag for that context whenever there is a change in that flag. Because flag values can have different data types, the value is reported using the general type LdValue.Go
Expand Go code sample
Expand Go code sample
The Go SDK provides a channel-based mechanism to notify you when flag configurations change. The To listen for changes in flag values for a specific flag key and context, use If you are using scoped clients, use
LDClient.GetFlagTracker() method returns an interface for this mechanism called FlagTracker.Calling GetFlagTracker().AddFlagChangeListener() provides a channel that receives a FlagChangeEvent whenever there is a change in any feature flag’s configuration. These changes include anything that could indirectly affect the flag value, such as a prerequisite flag or a segment that the flag uses.The event data consists only of the flag key. It does not contain a flag value, because in server-side SDKs, flags only have values when they are evaluated for a specific evaluation context.GetFlagTracker().AddFlagValueChangeListener(), which provides FlagValueChangeEvents. This is equivalent to re-evaluating the flag for that context whenever AddFlagChangeListener() reports a change in that flag. Because flag values can have different data types, the value is reported using the general type ldvalue.Value.CurrentContext() to pass in the scoped client’s current context. There is not an AddFlagValueChangeListener method in the LDScopedClient.With both of these methods, it is the caller’s responsibility to consume values from the channel. Letting values accumulate in the channel can cause an SDK goroutine to be blocked.Java
Expand Java code sample
Expand Java code sample
The SDK provides a listener-based mechanism to notify you when flag configurations change. The To listen for changes in flag values for a specific flag key and context, use
LDClient.getFlagTracker() method returns an interface for this mechanism, FlagTracker.Calling getFlagTracker().addFlagChangeListener calls your listener with a FlagChangeEvent whenever there is a change in any feature flag’s configuration, or in anything else that could indirectly affect the flag value, such as a prerequisite flag or a user segment that the flag uses.The event data consists only of the flag key. It does not contain a flag value, because in server-side SDKs, there is no such thing as a flag value except when it is evaluated for a specific set of user properties.The listener method is called from a worker thread.Here’s how:getFlagTracker().addFlagValueChangeListener, which provides FlagValueChangeEvents. This is equivalent to re-evaluating the flag for that context whenever addFlagChangeListener() reports a change in that flag. Because flag values can have different data types, the value is reported using the general type LDValue.Node.js (server-side)
Expand Node.js (server-side) code sample
Expand Node.js (server-side) code sample
The SDK provides an event-based mechanism to notify you when flag configurations change.For example, imagine you have a feature flag named
example-flag-key. If the SDK detects a change in example-flag-key’s configuration, or in anything else that could indirectly affect the flag value, such as a prerequisite flag or a user segment that example-flag-key uses, it emits two events.These events are:"update"and"update:example-flag-key"
"update:example-flag-key" if you only want to know about updates affecting that flag specifically, or "update" if you want to be notified about all updates.For both of these event kinds, an extra parameter is sent to event listeners. This object has the single property key, with its value set to the flag key. If you listened for the general "update" event, this lets you know which flag changed.The event parameter does not contain the flag value. In server-side SDKs, there is no such thing as a flag value except when it is evaluated for a specific set of user properties.To find out what the effect, if any, of the configuration change was, call variation() after receiving an update event.Here is an example:Python
Expand Python code sample
Expand Python code sample
The SDK provides a listener-based mechanism to notify you when flag configurations change. The To listen for changes in flag values for a specific flag key and context, use
LDClient#flag_tracker method returns an interface for this mechanism, FlagTracker.Calling flag_tracker.add_listener calls your listener with a FlagChange event whenever there is a change to any of the following:- the flag’s configuration
- the prerequisite flag’s configuration
- a segment used by the flag
flag_tracker.add_flag_value_change_listener, which provides FlagValueChange events. This is equivalent to re-evaluating the flag for that context whenever add_listener reports a change in that flag.Ruby
Expand Ruby code sample
Expand Ruby code sample
The SDK provides a listener-based mechanism to notify you when flag configurations change. The To listen for changes in flag values for a specific flag key and context, use
LDClient#flag_tracker method returns an interface for this mechanism, FlagTracker.Calling flag_tracker.add_listener calls your listener with a FlagChange event whenever there is a change to any of the following:- the flag’s configuration
- the prerequisite flag’s configuration
- a segment used by the flag
flag_tracker.add_flag_value_change_listener, which provides FlagValueChange events. This is equivalent to re-evaluating the flag for that context whenever add_listener reports a change in that flag.Roku
Expand Roku code sample
Expand Roku code sample
You can use Roku’s
observeField method on your node to respond to changes in flags.Here’s how: