File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -336,6 +336,19 @@ impl<E: Serialize + DeserializeOwned + Clone + PartialEq> Topic<E> {
336
336
337
337
self . modify ( |prev| if prev != msg { msg } else { None } ) ;
338
338
}
339
+
340
+ /// Wait until the topic is set to the specified value
341
+ #[ allow( dead_code) ]
342
+ pub async fn wait_for ( self : & Arc < Self > , val : E ) {
343
+ let ( mut stream, sub) = self . clone ( ) . subscribe_unbounded ( ) ;
344
+
345
+ // Unwrap here to keep the interface simple. The stream could only yield
346
+ // None if the sender side is dropped, which will not happen as we hold
347
+ // an Arc to self which contains the senders vec.
348
+ while stream. next ( ) . await . unwrap ( ) != val { }
349
+
350
+ sub. unsubscribe ( )
351
+ }
339
352
}
340
353
341
354
impl < E : Serialize + DeserializeOwned + Clone + Not + Not < Output = E > > Topic < E > {
You can’t perform that action at this time.
0 commit comments