@@ -178,26 +178,29 @@ impl DynamicRouteProvider {
178178 strategy : DynamicRoutingStrategy ,
179179 ) -> Result < Self , AgentError > {
180180 let seed_nodes: Result < Vec < _ > , _ > = seed_domains. into_iter ( ) . map ( Node :: new) . collect ( ) ;
181- let boxed = match strategy {
182- DynamicRoutingStrategy :: ByLatency => Box :: new (
183- DynamicRouteProviderBuilder :: new (
181+ let boxed: Box < dyn RouteProvider > = match strategy {
182+ DynamicRoutingStrategy :: ByLatency => {
183+ let provider = DynamicRouteProviderBuilder :: new (
184184 LatencyRoutingSnapshot :: new ( ) ,
185185 seed_nodes?,
186186 client,
187187 )
188- . build ( )
189- . await ,
190- ) as Box < dyn RouteProvider > ,
191- DynamicRoutingStrategy :: RoundRobin => Box :: new (
192- DynamicRouteProviderBuilder :: new (
188+ . build ( ) ;
189+ provider. start ( ) . await ;
190+ Box :: new ( provider)
191+ }
192+ DynamicRoutingStrategy :: RoundRobin => {
193+ let provider = DynamicRouteProviderBuilder :: new (
193194 RoundRobinRoutingSnapshot :: new ( ) ,
194195 seed_nodes?,
195196 client,
196197 )
197- . build ( )
198- . await ,
199- ) ,
198+ . build ( ) ;
199+ provider. start ( ) . await ;
200+ Box :: new ( provider)
201+ }
200202 } ;
203+
201204 Ok ( Self { inner : boxed } )
202205 }
203206 /// Same as [`run_in_background`](Self::run_in_background), but with custom intervals for refreshing the routing list and health-checking nodes.
@@ -209,30 +212,33 @@ impl DynamicRouteProvider {
209212 health_check_interval : Duration ,
210213 ) -> Result < Self , AgentError > {
211214 let seed_nodes: Result < Vec < _ > , _ > = seed_domains. into_iter ( ) . map ( Node :: new) . collect ( ) ;
212- let boxed = match strategy {
213- DynamicRoutingStrategy :: ByLatency => Box :: new (
214- DynamicRouteProviderBuilder :: new (
215+ let boxed: Box < dyn RouteProvider > = match strategy {
216+ DynamicRoutingStrategy :: ByLatency => {
217+ let provider = DynamicRouteProviderBuilder :: new (
215218 LatencyRoutingSnapshot :: new ( ) ,
216219 seed_nodes?,
217220 client,
218221 )
219222 . with_fetch_period ( list_update_interval)
220223 . with_check_period ( health_check_interval)
221- . build ( )
222- . await ,
223- ) as Box < dyn RouteProvider > ,
224- DynamicRoutingStrategy :: RoundRobin => Box :: new (
225- DynamicRouteProviderBuilder :: new (
224+ . build ( ) ;
225+ provider. start ( ) . await ;
226+ Box :: new ( provider)
227+ }
228+ DynamicRoutingStrategy :: RoundRobin => {
229+ let provider = DynamicRouteProviderBuilder :: new (
226230 RoundRobinRoutingSnapshot :: new ( ) ,
227231 seed_nodes?,
228232 client,
229233 )
230234 . with_fetch_period ( list_update_interval)
231235 . with_check_period ( health_check_interval)
232- . build ( )
233- . await ,
234- ) ,
236+ . build ( ) ;
237+ provider. start ( ) . await ;
238+ Box :: new ( provider)
239+ }
235240 } ;
241+
236242 Ok ( Self { inner : boxed } )
237243 }
238244}
0 commit comments