@@ -37,7 +37,7 @@ pub struct Client<A: Adapter> {
37
37
pub ( crate ) state : state:: TypeMap ![ Send + Sync ] ,
38
38
}
39
39
40
- /// ==== impl Client ====
40
+ // ==== impl Client ====
41
41
42
42
impl < A : Adapter > Client < A > {
43
43
pub fn new (
@@ -148,7 +148,7 @@ impl<A: Adapter> Client<A> {
148
148
}
149
149
150
150
/// Adds a new namespace handler
151
- pub async fn add_ns < C , T > ( & self , path : Cow < ' static , str > , callback : C ) -> Result < ( ) , A :: Error >
151
+ pub fn add_ns < C , T > ( & self , path : Cow < ' static , str > , callback : C )
152
152
where
153
153
C : ConnectHandler < A , T > ,
154
154
T : Send + Sync + ' static ,
@@ -162,9 +162,7 @@ impl<A: Adapter> Client<A> {
162
162
& self . adapter_state ,
163
163
self . config . parser ,
164
164
) ;
165
- ns. adapter . clone ( ) . init ( ) . await ?;
166
165
self . nsps . write ( ) . unwrap ( ) . insert ( path, ns) ;
167
- Ok ( ( ) )
168
166
}
169
167
170
168
pub fn add_dyn_ns < C , T > ( & self , path : String , callback : C ) -> Result < ( ) , matchit:: InsertError >
@@ -179,6 +177,16 @@ impl<A: Adapter> Client<A> {
179
177
self . router . write ( ) . unwrap ( ) . insert ( path, ns)
180
178
}
181
179
180
+ /// Initializes all the namespace handlers
181
+ ///
182
+ /// If an any error occurs while initializing a namespace, it is immediately returned
183
+ pub async fn init_nsps ( & self ) -> Result < ( ) , A :: Error > {
184
+ let nsps: Vec < _ > = self . nsps . read ( ) . unwrap ( ) . values ( ) . cloned ( ) . collect ( ) ;
185
+ let futures = nsps. into_iter ( ) . map ( |ns| ns. adapter . clone ( ) . init ( ) ) ;
186
+ futures_util:: future:: try_join_all ( futures) . await ?;
187
+ Ok ( ( ) )
188
+ }
189
+
182
190
/// Deletes a namespace handler and closes all the connections to it
183
191
pub fn delete_ns ( & self , path : & str ) {
184
192
#[ cfg( feature = "v4" ) ]
0 commit comments