Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Adding a close method (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoskow-ld authored Nov 25, 2019
1 parent 6e27caa commit 6dafe43
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public String getName() {
// Constants used in promise rejection
private static final String ERROR_INIT = "E_INITIALIZE";
private static final String ERROR_IDENTIFY = "E_IDENTIFY";
private static final String ERROR_CLOSE = "E_CLOSE";
private static final String ERROR_UNKNOWN = "E_UNKNOWN";

// Prefix for events sent over the React Native event bridge
Expand Down Expand Up @@ -786,6 +787,19 @@ public void flush() {
ldClient.flush();
}

/**
* Triggers a background flush and then closes all connections to LaunchDarkly.
*/
@ReactMethod
public void close(Promise promise) {
try {
ldClient.close();
promise.resolve(true);
} catch (Exception e) {
promise.reject(ERROR_CLOSE, e);
}
}

/**
* Calls LaunchDarkly's identify call that selects the user flags are pulled for, and tracking
* events refer to.
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export default class LDClient {
LaunchdarklyReactNativeClient.flush();
}

close() {
LaunchdarklyReactNativeClient.close();
}

identify(userConfig) {
return LaunchdarklyReactNativeClient.identify(userConfig);
}
Expand Down
5 changes: 5 additions & 0 deletions ios/LaunchdarklyReactNativeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
LDClient.shared.reportEvents()
}

@objc func close(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
LDClient.shared.stop()
resolve(true)
}

@objc func identify(_ options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
let user = userBuild(userConfig: options)
if let usr = user {
Expand Down
2 changes: 2 additions & 0 deletions ios/LaunchdarklyReactNativeClientBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ @interface RCT_EXTERN_MODULE(LaunchdarklyReactNativeClient, RCTEventEmitter)

RCT_EXTERN_METHOD(flush)

RCT_EXTERN_METHOD(close:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(identify:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(allFlags:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
Expand Down

0 comments on commit 6dafe43

Please sign in to comment.