Skip to content
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

fix: make passing of LD_NONBLOCKING in C bindings consistent #107

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" { // only need to export C interface if

typedef struct _LDClientSDK* LDClientSDK;

#define LD_NONBLOCKING -1
#define LD_NONBLOCKING 0
#define LD_DISCARD_DETAIL NULL

/**
Expand Down Expand Up @@ -90,13 +90,13 @@ LDClientSDK_TrackData(LDClientSDK sdk, char const* event_name, LDValue data);
/**
* Requests delivery of all pending analytic events (if any).
*
* Pass LD_NONBLOCKING as the second parameter.
* You MUST pass LD_NONBLOCKING as the second parameter.
*
* @param sdk SDK. Must not be NULL.
* @param milliseconds Must pass LD_NONBLOCKING.
*/
LD_EXPORT(void)
LDClientSDK_Flush(LDClientSDK sdk, int reserved);
LDClientSDK_Flush(LDClientSDK sdk, unsigned int reserved);

/**
* Changes the current evaluation context, requests flags for that context
Expand All @@ -107,7 +107,7 @@ LDClientSDK_Flush(LDClientSDK sdk, int reserved);
* concurrently invokes undefined behavior.
*
* To block until the identify operation is complete or a timeout is reached,
* pass a non-negative milliseconds parameter. Otherwise to return immediately,
* pass a positive milliseconds parameter. Otherwise to return immediately,
* pass LD_NONBLOCKING.
*
* @param sdk SDK. Must not be NULL.
Expand All @@ -116,7 +116,9 @@ LDClientSDK_Flush(LDClientSDK sdk, int reserved);
* LD_NONBLOCKING to return immediately.
*/
LD_EXPORT(void)
LDClientSDK_Identify(LDClientSDK sdk, LDContext context, int milliseconds);
LDClientSDK_Identify(LDClientSDK sdk,
LDContext context,
unsigned int milliseconds);

/**
* Returns the boolean value of a feature flag for a given flag key.
Expand Down
8 changes: 5 additions & 3 deletions libs/client-sdk/src/bindings/c/sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ LDClientSDK_TrackData(LDClientSDK sdk, char const* event_name, LDValue value) {
}

LD_EXPORT(void)
LDClientSDK_Flush(LDClientSDK sdk, int reserved) {
LDClientSDK_Flush(LDClientSDK sdk, unsigned int reserved) {
LD_ASSERT_NOT_NULL(sdk);
LD_ASSERT(reserved == LD_NONBLOCKING);
TO_SDK(sdk)->FlushAsync();
}

LD_EXPORT(void)
LDClientSDK_Identify(LDClientSDK sdk, LDContext context, int milliseconds) {
LDClientSDK_Identify(LDClientSDK sdk,
LDContext context,
unsigned int milliseconds) {
LD_ASSERT_NOT_NULL(sdk);
LD_ASSERT_NOT_NULL(context);

Expand All @@ -118,7 +120,7 @@ LDClientSDK_Identify(LDClientSDK sdk, LDContext context, int milliseconds) {

LDContext_Free(context);

if (milliseconds < 0) {
if (milliseconds == LD_NONBLOCKING) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also just call wait_for with 0, but I believe there's no guarantee that won't block for some tiny amount of time.


Expand Down