Module: LaunchDarkly::Interfaces::FlagTracker

Included in:
LaunchDarkly::Impl::FlagTracker
Defined in:
lib/ldclient-rb/interfaces.rb

Overview

An interface for tracking changes in feature flag configurations.

An implementation of this interface is returned by LDClient#flag_tracker. Application code never needs to implement this interface.

Instance Method Summary collapse

Instance Method Details

#add_flag_value_change_listener(key, context, listener) ⇒ Object

Registers a listener to be notified of a change in a specific feature flag’s value for a specific evaluation context.

When you call this method, it first immediately evaluates the feature flag. It then uses #add_listener to start listening for feature flag configuration changes, and whenever the specified feature flag changes, it re-evaluates the flag for the same context. It then calls your listener if and only if the resulting value has changed.

All feature flag evaluations require an instance of LDContext. If the feature flag you are tracking does not have any context targeting rules, you must still pass a dummy context such as ‘LDContext.with_key(“for-global-flags”)`. If you do not want the user to appear on your dashboard, use the anonymous property: `LDContext.create(“for-global-flags”, kind: “user”, anonymous: true)`.

The returned listener represents the subscription that was created by this method call; to unsubscribe, pass that object (not your listener) to #remove_listener.

Parameters:



237
# File 'lib/ldclient-rb/interfaces.rb', line 237

def add_flag_value_change_listener(key, context, listener) end

#add_listener(listener) ⇒ Object

Registers a listener to be notified of feature flag changes in general.

The listener will be notified whenever the SDK receives any change to any feature flag’s configuration, or to a user segment that is referenced by a feature flag. If the updated flag is used as a prerequisite for other flags, the SDK assumes that those flags may now behave differently and sends flag change events for them as well.

Note that this does not necessarily mean the flag’s value has changed for any particular evaluation context, only that some part of the flag configuration was changed so that it may return a different value than it previously returned for some context. If you want to track flag value changes, use #add_flag_value_change_listener instead.

It is possible, given current design restrictions, that a listener might be notified when no change has occurred. This edge case will be addressed in a later version of the SDK. It is important to note this issue does not affect #add_flag_value_change_listener listeners.

If using the file data source, any change in a data file will be treated as a change to every flag. Again, use #add_flag_value_change_listener (or just re-evaluate the flag # yourself) if you want to know whether this is a change that really affects a flag’s value.

Change events only work if the SDK is actually connecting to LaunchDarkly (or using the file data source). If the SDK is only reading flags from a database then it cannot know when there is a change, because flags are read on an as-needed basis.

The listener will be called from a worker thread.

Calling this method for an already-registered listener has no effect.

Parameters:

  • listener (#update)


205
# File 'lib/ldclient-rb/interfaces.rb', line 205

def add_listener(listener) end

#remove_listener(listener) ⇒ Object

Unregisters a listener so that it will no longer be notified of feature flag changes.

Calling this method for a listener that was not previously registered has no effect.

Parameters:

  • listener (Object)


214
# File 'lib/ldclient-rb/interfaces.rb', line 214

def remove_listener(listener) end