Skip to content

Commit 7a8e98e

Browse files
author
jianggang
committed
feat: add sync_once function
1 parent 3c43f75 commit 7a8e98e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
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 = ["maintain@featureprobe.com"]
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_once(&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 {

0 commit comments

Comments
 (0)