@@ -7,14 +7,15 @@ use crate::conversion::{convert_attributes, convert_value_term, convert_event_te
7
7
use crate :: assignment:: { get_assignment_inner, get_assignment_details_inner} ;
8
8
use eppo_core:: {
9
9
configuration_fetcher:: { ConfigurationFetcher , ConfigurationFetcherConfig } ,
10
- configuration_poller:: { start_configuration_poller, ConfigurationPollerConfig } ,
10
+ configuration_poller:: { start_configuration_poller, ConfigurationPollerConfig , ConfigurationPoller } ,
11
11
configuration_store:: ConfigurationStore ,
12
12
eval:: { Evaluator , EvaluatorConfig } ,
13
13
ufc:: VariationType ,
14
14
SdkMetadata ,
15
15
background:: BackgroundThread ,
16
16
} ;
17
17
use std:: panic:: { RefUnwindSafe , UnwindSafe } ;
18
+ use std:: time:: Duration ;
18
19
19
20
use rustler:: { Encoder , Env , NifResult , ResourceArc , Term } ;
20
21
use rustler:: types:: atom;
@@ -27,8 +28,9 @@ const SDK_METADATA: SdkMetadata = SdkMetadata {
27
28
} ;
28
29
29
30
pub struct EppoClient {
30
- pub evaluator : Evaluator ,
31
- pub background_thread : BackgroundThread ,
31
+ evaluator : Evaluator ,
32
+ background_thread : BackgroundThread ,
33
+ configuration_poller : ConfigurationPoller ,
32
34
}
33
35
34
36
#[ rustler:: resource_impl]
@@ -62,7 +64,7 @@ fn init(config: Config) -> NifResult<ResourceArc<EppoClient>> {
62
64
) )
63
65
. with_jitter ( std:: time:: Duration :: from_secs ( config. poll_jitter_seconds ) ) ;
64
66
65
- let _poller = start_configuration_poller (
67
+ let poller = start_configuration_poller (
66
68
background_thread. runtime ( ) ,
67
69
fetcher,
68
70
store. clone ( ) ,
@@ -78,6 +80,7 @@ fn init(config: Config) -> NifResult<ResourceArc<EppoClient>> {
78
80
let client = ResourceArc :: new ( EppoClient {
79
81
evaluator,
80
82
background_thread,
83
+ configuration_poller : poller,
81
84
} ) ;
82
85
83
86
Ok ( client)
@@ -151,4 +154,29 @@ fn get_assignment_details<'a>(
151
154
}
152
155
}
153
156
157
+ #[ rustler:: nif]
158
+ fn wait_for_initialization (
159
+ client : ResourceArc < EppoClient > ,
160
+ timeout_secs : f64 ,
161
+ ) -> NifResult < ( ) > {
162
+ log:: info!( target: "eppo" , "waiting for initialization" ) ;
163
+
164
+ let _ = client
165
+ . background_thread
166
+ . runtime ( )
167
+ . async_runtime
168
+ . block_on ( async {
169
+ tokio:: time:: timeout (
170
+ Duration :: from_secs_f64 ( timeout_secs) ,
171
+ client. configuration_poller . wait_for_configuration ( ) ,
172
+ )
173
+ . await
174
+ } )
175
+ . inspect_err ( |err| {
176
+ log:: warn!( target: "eppo" , "failed to wait for initialization: {:?}" , err) ;
177
+ } ) ;
178
+
179
+ Ok ( ( ) )
180
+ }
181
+
154
182
rustler:: init!( "Elixir.EppoSdk.Core" ) ;
0 commit comments