Skip to content

Commit 4e57cc6

Browse files
authored
Merge pull request #21 from FeatureProbe/sync_once_func
feat: add sync_once func
2 parents 3c43f75 + 0e66a42 commit 4e57cc6

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "feature-probe-server-sdk"
4-
version = "1.2.7"
4+
version = "1.2.8"
55
license = "Apache-2.0"
66
authors = ["[email protected]"]
77
description = "FeatureProbe Server Side SDK for Rust"

src/feature_probe.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::fmt::Debug;
77
use std::sync::Arc;
88
use tracing::trace;
99

10+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
11+
use crate::sync::SyncType;
1012
use crate::{
1113
config::Config,
1214
evaluate::{EvalDetail, Repository},
@@ -248,6 +250,18 @@ impl FeatureProbe {
248250
syncer.start_sync(self.config.start_wait, self.should_stop.clone());
249251
}
250252

253+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
254+
pub fn sync_now(&self, t: SyncType) {
255+
trace!("sync now url {}", &self.config.toggles_url);
256+
let syncer = match &self.syncer {
257+
Some(syncer) => syncer.clone(),
258+
None => return,
259+
};
260+
tokio::spawn(async move {
261+
syncer.sync_now(t).await.expect("sync once error");
262+
});
263+
}
264+
251265
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
252266
fn connect_socket(&mut self) {
253267
let mut slf = self.clone();
@@ -297,8 +311,6 @@ impl FeatureProbe {
297311

298312
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
299313
fn socket_on_update(slf: Self, payload: Option<socketio_rs::Payload>) -> SocketCallback {
300-
use crate::sync::SyncType;
301-
302314
trace!("socket_on_update: {:?}", payload);
303315
async move {
304316
if let Some(syncer) = &slf.syncer {

tests/integration_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ async fn integration_test() {
3535
};
3636

3737
let mut fp = FeatureProbe::new(config);
38-
38+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
39+
fp.sync_now(SyncType::Polling);
3940
let did_update = {
4041
let did_update = Arc::new(Mutex::new((false, false)));
4142
let did_update_clone = did_update.clone();

0 commit comments

Comments
 (0)