@@ -102,10 +102,38 @@ pub async fn logged_in_client_with_server() -> (Client, wiremock::MockServer) {
102
102
( client, server)
103
103
}
104
104
105
- /// Asserts the next item in a `Stream` or `Subscriber` can be loaded in the
106
- /// given timeout in the given timeout in milliseconds.
105
+ /// Asserts that the next item in a `Stream` is received within a given timeout.
106
+ ///
107
+ /// This macro waits for the next item from an asynchronous `Stream` or, if no
108
+ /// item is received within the specified timeout, the macro panics.
109
+ ///
110
+ /// # Parameters
111
+ ///
112
+ /// - `$stream`: The `Stream` or `Subscriber` to poll for the next item.
113
+ /// - `$timeout_ms` (optional): The timeout in milliseconds to wait for the next
114
+ /// item. Defaults to 500ms if not provided.
115
+ ///
116
+ /// # Example
117
+ ///
118
+ /// ```rust
119
+ /// use futures_util::{stream, StreamExt};
120
+ /// use matrix_sdk::assert_next_with_timeout;
121
+ ///
122
+ /// # async {
123
+ /// let mut stream = stream::iter(vec![1, 2, 3]);
124
+ /// let next_item = assert_next_with_timeout!(stream, 1000); // Waits up to 1000ms
125
+ /// assert_eq!(next_item, 1);
126
+ ///
127
+ /// // The timeout can be omitted, in which case it defaults to 500 ms.
128
+ /// let next_item = assert_next_with_timeout!(stream); // Waits up to 500ms
129
+ /// assert_eq!(next_item, 2);
130
+ /// # };
131
+ /// ```
107
132
#[ macro_export]
108
133
macro_rules! assert_next_with_timeout {
134
+ ( $stream: expr) => {
135
+ $crate:: assert_next_with_timeout!( $stream, 500 )
136
+ } ;
109
137
( $stream: expr, $timeout_ms: expr) => { {
110
138
// Needed for subscribers, as they won't use the StreamExt features
111
139
#[ allow( unused_imports) ]
0 commit comments