Skip to content

Commit 9f991c4

Browse files
authored
Merge pull request #12 from Flagsmith/release/v1.1.0
Release/v1.1.0
2 parents 6841e36 + ba919e7 commit 9f991c4

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flagsmith"
3-
version = "1.0.1"
3+
version = "1.1.0"
44
authors = ["Gagan Trivedi <[email protected]>"]
55
edition = "2021"
66
license = "BSD-3-Clause"
@@ -20,6 +20,7 @@ reqwest = { version = "0.11", features = ["json", "blocking"] }
2020
url = "2.1"
2121
chrono = { version = "0.4"}
2222
log = "0.4"
23+
flume = "0.10.14"
2324

2425
flagsmith-flag-engine = "0.1.1"
2526

example/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Flagsmith Basic Rust Example
22

3-
This directory contains a basic Rocket application which utilises Flagsmith. To run the example application, you'll
3+
This directory contains a basic Rocket application which utilises Flagsmith. To run the example application, you'll
44
need to go through the following steps:
55

66
1. Create an account, organisation and project on [Flagsmith](https://flagsmith.com)
77
2. Create a feature in the project called "secret_button"
8-
3. Give the feature a value using the json editor as follows:
8+
3. Give the feature a value using the json editor as follows:
99

1010
```json
1111
{"colour": "#ababab"}
1212
```
1313

14-
4. Set the environment variable `FLAGSMITH_ENVIRONMENT_KEY` with the environment key of one of the environments
14+
4. Set the environment variable `FLAGSMITH_ENVIRONMENT_KEY` with the environment key of one of the environments
1515
in flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.)
1616
5. Run the app using `cargo run`
1717
6. Browse to http://localhost:5000
1818

1919
Now you can play around with the 'secret_button' feature in flagsmith, turn it on to show it and edit the colour in the
2020
json value to edit the colour of the button. You can also identify as a given user and then update the settings for the
21-
secret button feature for that user in the flagsmith interface to see the affect that has too.
21+
secret button feature for that user in the flagsmith interface to see the affect that has too.

src/flagsmith/analytics.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use log::{debug, warn};
22
use reqwest::header::HeaderMap;
33
use serde_json;
4-
use std::sync::mpsc;
5-
use std::sync::mpsc::{Sender, TryRecvError};
4+
use flume;
65
use std::{collections::HashMap, thread};
76

87
use std::sync::{Arc, RwLock};
98
static ANALYTICS_TIMER_IN_MILLI: u64 = 10 * 1000;
109

1110
#[derive(Clone, Debug)]
1211
pub struct AnalyticsProcessor {
13-
pub tx: Sender<String>,
12+
pub tx: flume::Sender<String>,
1413
_analytics_data: Arc<RwLock<HashMap<String, u32>>>,
1514
}
1615

@@ -21,7 +20,7 @@ impl AnalyticsProcessor {
2120
timeout: std::time::Duration,
2221
timer: Option<u64>,
2322
) -> Self {
24-
let (tx, rx) = mpsc::channel::<String>();
23+
let (tx, rx) = flume::unbounded();
2524
let client = reqwest::blocking::Client::builder()
2625
.default_headers(headers)
2726
.timeout(timeout)
@@ -49,8 +48,8 @@ impl AnalyticsProcessor {
4948
.and_modify(|e| *e += 1)
5049
.or_insert(1);
5150
}
52-
Err(TryRecvError::Empty) => {}
53-
Err(TryRecvError::Disconnected) => {
51+
Err(flume::TryRecvError::Empty) => {}
52+
Err(flume::TryRecvError::Disconnected) => {
5453
debug!("Shutting down analytics thread ");
5554
break;
5655
}

src/flagsmith/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mod models;
1414
use self::analytics::AnalyticsProcessor;
1515
use self::models::{Flag, Flags};
1616
use super::error;
17-
use std::sync::mpsc::{self, Sender, TryRecvError};
17+
use std::sync::mpsc::{self, SyncSender, TryRecvError};
1818

1919
const DEFAULT_API_URL: &str = "https://edge.api.flagsmith.com/api/v1/";
2020

@@ -50,7 +50,7 @@ pub struct Flagsmith {
5050
options: FlagsmithOptions,
5151
datastore: Arc<Mutex<DataStore>>,
5252
analytics_processor: Option<AnalyticsProcessor>,
53-
_polling_thead_tx: Sender<u32>, // used for shutting down polling manager
53+
_polling_thread_tx: SyncSender<u32>, // to trigger polling manager shutdown
5454
}
5555

5656
struct DataStore {
@@ -88,7 +88,7 @@ impl Flagsmith {
8888
// Put the environment model behind mutex to
8989
// to share it safely between threads
9090
let ds = Arc::new(Mutex::new(DataStore { environment: None }));
91-
let (tx, rx) = mpsc::channel::<u32>();
91+
let (tx, rx) = mpsc::sync_channel::<u32>(1);
9292
let flagsmith = Flagsmith {
9393
client: client.clone(),
9494
environment_flags_url,
@@ -97,7 +97,7 @@ impl Flagsmith {
9797
options: flagsmith_options,
9898
datastore: Arc::clone(&ds),
9999
analytics_processor,
100-
_polling_thead_tx: tx,
100+
_polling_thread_tx: tx,
101101
};
102102

103103
// Create a thread to update environment document
@@ -368,6 +368,14 @@ mod tests {
368368
"feature_states": []
369369
}"#;
370370

371+
#[test]
372+
fn client_implements_send_and_sync(){
373+
// Given
374+
fn implements_send_and_sync<T: Send + Sync>() {}
375+
// Then
376+
implements_send_and_sync::<Flagsmith>();
377+
}
378+
371379
#[test]
372380
fn polling_thread_updates_environment_on_start() {
373381
// Given
@@ -391,6 +399,7 @@ mod tests {
391399
};
392400
// When
393401
let _flagsmith = Flagsmith::new(environment_key.to_string(), flagsmith_options);
402+
394403
// let's wait for the thread to make the request
395404
thread::sleep(std::time::Duration::from_millis(50));
396405
// Then

0 commit comments

Comments
 (0)