-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow waiting for the network response on identify. #548
Changes from 4 commits
6d2a29a
0e3c754
267ec1e
86c2d70
3f22050
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -217,7 +217,6 @@ export default class LDClientImpl implements LDClient { | |||||
}, | ||||||
{}, | ||||||
); | ||||||
|
||||||
await this.flagManager.init(context, descriptors).then(identifyResolve()); | ||||||
}, | ||||||
}); | ||||||
|
@@ -320,6 +319,9 @@ export default class LDClientImpl implements LDClient { | |||||
* 3. A network error is encountered during initialization. | ||||||
*/ | ||||||
async identify(pristineContext: LDContext, identifyOptions?: LDIdentifyOptions): Promise<void> { | ||||||
// In offline mode we do not support waiting for results. | ||||||
const waitForNetworkResults = !!identifyOptions?.waitForNetworkResults && !this.isOffline(); | ||||||
|
||||||
if (identifyOptions?.timeout) { | ||||||
this.identifyTimeout = identifyOptions.timeout; | ||||||
} | ||||||
|
@@ -354,15 +356,23 @@ export default class LDClientImpl implements LDClient { | |||||
this.logger.debug(`Identifying ${JSON.stringify(this.checkedContext)}`); | ||||||
|
||||||
const loadedFromCache = await this.flagManager.loadCached(this.checkedContext); | ||||||
if (loadedFromCache) { | ||||||
if (loadedFromCache && !waitForNetworkResults) { | ||||||
this.logger.debug('Identify completing with cached flags'); | ||||||
identifyResolve(); | ||||||
} | ||||||
if (loadedFromCache && waitForNetworkResults) { | ||||||
this.logger.debug( | ||||||
'Identify - Flags loaded from cache, but identify was requested with "waitForNetworkResults"', | ||||||
); | ||||||
} | ||||||
|
||||||
if (this.isOffline()) { | ||||||
if (loadedFromCache) { | ||||||
this.logger.debug('Offline identify using storage flags.'); | ||||||
this.logger.debug('Offline identify - using cached flags.'); | ||||||
} else { | ||||||
this.logger.debug('Offline identify no storage. Defaults will be used.'); | ||||||
this.logger.debug( | ||||||
'Offline identify - no cached flags, using defaults or already loaded flags.', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small suggestion for clarity. I had to think a bit to realize what this was conveying.
Suggested change
Is the trailing comma intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our linting requires training coma for parameters that are not on one line. The linter also forces this line to be wrapped as such. |
||||||
); | ||||||
identifyResolve(); | ||||||
} | ||||||
} else { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,16 @@ export interface LDIdentifyOptions { | |
* Defaults to 5 seconds. | ||
*/ | ||
timeout: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kinyoklion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately timeout was already implemented as non-optional. That said it defaults to 5, so setting it to 5 is equal to not providing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will consider it. There are advantages to having it non-optional and some SDKs require it with every call identify. Which makes it more obvious that the operation can timeout. We document it, but people are still often surprised that it times out. |
||
|
||
/** | ||
* When true indicates that the SDK will attempt to wait for values from | ||
* LaunchDarkly instead of depending on cached values. The cached values will | ||
* still be loaded, but the promise returned by the identify function will not | ||
* resolve as a result of those cached values being loaded. Generally this | ||
* option should NOT be used and instead flag changes should be listened to. | ||
* It the client is set to offline mode, then this option is ignored. | ||
kinyoklion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Defaults to false. | ||
*/ | ||
waitForNetworkResults?: boolean; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decreasing the scope of these to the fixture.