Skip to content

Commit 1913dd4

Browse files
committed
feat: get init status
1 parent 3cd99ae commit 1913dd4

File tree

6 files changed

+202
-47
lines changed

6 files changed

+202
-47
lines changed

examples/demo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn main() {
1717
refresh_interval: interval,
1818
#[cfg(feature = "use_tokio")]
1919
http_client: None,
20-
wait_first_resp: true,
20+
start_wait: Some(Duration::from_secs(5)),
2121
..Default::default()
2222
};
2323

src/evalutate.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,7 @@ fn validate_toggle(_toggle: &Toggle) -> Result<(), FPError> {
495495

496496
#[allow(dead_code)]
497497
pub fn load_json(json_str: &str) -> Result<Repository, FPError> {
498-
let repo =
499-
serde_json::from_str::<Repository>(json_str).map_err(|e| FPError::JsonError(e.to_string()));
498+
let repo = serde_json::from_str::<Repository>(json_str).map_err(FPError::JsonError);
500499
if let Ok(repo) = &repo {
501500
for t in repo.toggles.values() {
502501
validate_toggle(t)?
@@ -1116,8 +1115,7 @@ mod condition_tests {
11161115
}
11171116
"#;
11181117

1119-
let segment = serde_json::from_str::<Condition>(json_str)
1120-
.map_err(|e| FPError::JsonError(e.to_string()));
1118+
let segment = serde_json::from_str::<Condition>(json_str).map_err(FPError::JsonError);
11211119
assert!(segment.is_ok())
11221120
}
11231121

src/feature_probe.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ impl FeatureProbe {
128128
*should_stop = true;
129129
}
130130

131+
pub fn initialized(&self) -> bool {
132+
match &self.syncer {
133+
Some(s) => s.initialized(),
134+
None => false,
135+
}
136+
}
137+
131138
fn generic_detail<T: Default + Debug>(
132139
&self,
133140
toggle: &str,
@@ -212,8 +219,8 @@ impl FeatureProbe {
212219
self.config.http_client.clone(),
213220
repo,
214221
);
215-
syncer.sync(self.config.wait_first_resp, self.should_stop.clone());
216-
self.syncer = Some(syncer);
222+
self.syncer = Some(syncer.clone());
223+
syncer.sync(self.config.start_wait, self.should_stop.clone())?;
217224
Ok(())
218225
}
219226

@@ -254,7 +261,7 @@ pub struct FPConfig {
254261
pub refresh_interval: Duration,
255262
#[cfg(feature = "use_tokio")]
256263
pub http_client: Option<Client>,
257-
pub wait_first_resp: bool,
264+
pub start_wait: Option<Duration>,
258265
}
259266

260267
#[derive(Debug, Default, Clone)]
@@ -265,7 +272,7 @@ pub struct InnerConfig {
265272
pub refresh_interval: Duration,
266273
#[cfg(feature = "use_tokio")]
267274
pub http_client: Option<Client>,
268-
pub wait_first_resp: bool,
275+
pub start_wait: Option<Duration>,
269276
}
270277

271278
fn build_config(mut config: FPConfig) -> InnerConfig {
@@ -285,7 +292,7 @@ fn build_config(mut config: FPConfig) -> InnerConfig {
285292
events_url: config.events_url.expect("not none"),
286293
server_sdk_key: config.server_sdk_key,
287294
refresh_interval: config.refresh_interval,
288-
wait_first_resp: config.wait_first_resp,
295+
start_wait: config.start_wait,
289296
#[cfg(feature = "use_tokio")]
290297
http_client: config.http_client,
291298
}
@@ -401,7 +408,7 @@ mod server_sdk_contract_tests {
401408

402409
#[allow(dead_code)]
403410
pub(crate) fn load_tests_json(json_str: &str) -> Result<Tests, FPError> {
404-
serde_json::from_str::<Tests>(json_str).map_err(|e| FPError::JsonError(e.to_string()))
411+
serde_json::from_str::<Tests>(json_str).map_err(FPError::JsonError)
405412
}
406413

407414
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ pub struct FPDetail<T: Default + Debug> {
3434
#[derive(Debug, Error)]
3535
pub enum FPError {
3636
#[error("invalid json: {0}")]
37-
JsonError(String),
37+
JsonError(#[from] serde_json::Error),
3838
#[error("invalid url: {0}")]
3939
UrlError(String),
40+
#[error("http error: {0}")]
41+
HttpError(String),
4042
#[error("evaluation error")]
4143
EvalError,
4244
#[error("evaluation error: {0}")]
4345
EvalDetailError(String),
46+
#[error("internal error: {0}")]
47+
InternalError(String),
4448
}
4549

4650
#[derive(Debug, Deserialize)]

0 commit comments

Comments
 (0)