Skip to content

Commit 36f56b5

Browse files
authored
fix: make passing of LD_NONBLOCKING in C bindings consistent (#107)
Before, the asynchronous methods (`Flush`/`Identify`) were taking a signed int milliseconds argument, where negative represented nonblocking, and 0/positive numbers were a delay. This reduces the state to simply 0/positive numbers. `LD_NONBLOCKING` is defined as 0. There's no point having a 3rd state for nonblocking.
1 parent 54ce7f9 commit 36f56b5

File tree

2 files changed

+12
-8
lines changed
  • libs/client-sdk
    • include/launchdarkly/client_side/bindings/c
    • src/bindings/c

2 files changed

+12
-8
lines changed

libs/client-sdk/include/launchdarkly/client_side/bindings/c/sdk.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" { // only need to export C interface if
1818

1919
typedef struct _LDClientSDK* LDClientSDK;
2020

21-
#define LD_NONBLOCKING -1
21+
#define LD_NONBLOCKING 0
2222
#define LD_DISCARD_DETAIL NULL
2323

2424
/**
@@ -90,13 +90,13 @@ LDClientSDK_TrackData(LDClientSDK sdk, char const* event_name, LDValue data);
9090
/**
9191
* Requests delivery of all pending analytic events (if any).
9292
*
93-
* Pass LD_NONBLOCKING as the second parameter.
93+
* You MUST pass LD_NONBLOCKING as the second parameter.
9494
*
9595
* @param sdk SDK. Must not be NULL.
9696
* @param milliseconds Must pass LD_NONBLOCKING.
9797
*/
9898
LD_EXPORT(void)
99-
LDClientSDK_Flush(LDClientSDK sdk, int reserved);
99+
LDClientSDK_Flush(LDClientSDK sdk, unsigned int reserved);
100100

101101
/**
102102
* Changes the current evaluation context, requests flags for that context
@@ -107,7 +107,7 @@ LDClientSDK_Flush(LDClientSDK sdk, int reserved);
107107
* concurrently invokes undefined behavior.
108108
*
109109
* To block until the identify operation is complete or a timeout is reached,
110-
* pass a non-negative milliseconds parameter. Otherwise to return immediately,
110+
* pass a positive milliseconds parameter. Otherwise to return immediately,
111111
* pass LD_NONBLOCKING.
112112
*
113113
* @param sdk SDK. Must not be NULL.
@@ -116,7 +116,9 @@ LDClientSDK_Flush(LDClientSDK sdk, int reserved);
116116
* LD_NONBLOCKING to return immediately.
117117
*/
118118
LD_EXPORT(void)
119-
LDClientSDK_Identify(LDClientSDK sdk, LDContext context, int milliseconds);
119+
LDClientSDK_Identify(LDClientSDK sdk,
120+
LDContext context,
121+
unsigned int milliseconds);
120122

121123
/**
122124
* Returns the boolean value of a feature flag for a given flag key.

libs/client-sdk/src/bindings/c/sdk.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ LDClientSDK_TrackData(LDClientSDK sdk, char const* event_name, LDValue value) {
102102
}
103103

104104
LD_EXPORT(void)
105-
LDClientSDK_Flush(LDClientSDK sdk, int reserved) {
105+
LDClientSDK_Flush(LDClientSDK sdk, unsigned int reserved) {
106106
LD_ASSERT_NOT_NULL(sdk);
107107
LD_ASSERT(reserved == LD_NONBLOCKING);
108108
TO_SDK(sdk)->FlushAsync();
109109
}
110110

111111
LD_EXPORT(void)
112-
LDClientSDK_Identify(LDClientSDK sdk, LDContext context, int milliseconds) {
112+
LDClientSDK_Identify(LDClientSDK sdk,
113+
LDContext context,
114+
unsigned int milliseconds) {
113115
LD_ASSERT_NOT_NULL(sdk);
114116
LD_ASSERT_NOT_NULL(context);
115117

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

119121
LDContext_Free(context);
120122

121-
if (milliseconds < 0) {
123+
if (milliseconds == LD_NONBLOCKING) {
122124
return;
123125
}
124126

0 commit comments

Comments
 (0)