Skip to content

Commit 3568cf7

Browse files
author
jianggang
committed
feat: add sync_once function
1 parent 3c43f75 commit 3568cf7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/feature_probe.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ use std::collections::HashMap;
66
use std::fmt::Debug;
77
use std::sync::Arc;
88
use tracing::trace;
9-
10-
use crate::{
11-
config::Config,
12-
evaluate::{EvalDetail, Repository},
13-
};
9+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
10+
use crate::sync::SyncType;
11+
use crate::{config::Config, evaluate::{EvalDetail, Repository}};
1412
use crate::{sync::Synchronizer, FPConfig};
1513
use crate::{sync::UpdateCallback, user::FPUser};
1614
use crate::{FPDetail, SdkAuthorization, Toggle};
@@ -248,6 +246,18 @@ impl FeatureProbe {
248246
syncer.start_sync(self.config.start_wait, self.should_stop.clone());
249247
}
250248

249+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
250+
pub fn sync_once(&self , t: SyncType) {
251+
trace!("sync now url {}", &self.config.toggles_url);
252+
let syncer = match &self.syncer {
253+
Some(syncer) => syncer.clone(),
254+
None => return,
255+
};
256+
tokio::spawn(async move {
257+
syncer.sync_now(t).await.expect("sync once error");
258+
});
259+
}
260+
251261
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
252262
fn connect_socket(&mut self) {
253263
let mut slf = self.clone();
@@ -297,7 +307,6 @@ impl FeatureProbe {
297307

298308
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
299309
fn socket_on_update(slf: Self, payload: Option<socketio_rs::Payload>) -> SocketCallback {
300-
use crate::sync::SyncType;
301310

302311
trace!("socket_on_update: {:?}", payload);
303312
async move {

0 commit comments

Comments
 (0)