Commit 4d2ad0e
Allow calling UnboundedReceiver::try_next after None
Allow calling `UnboundedReceiver::try_next` and `Receiver::try_next`
after `None`: do not panic.
Not-panicking is equally safe, and does not have negative performance
implication.
It is irrelevant for `Stream` implementation to panic or not (because
`Stream` behavior is unspecified after `None`), but panicking in
`try_next` just complicates the interface: returned `Ok(None)` is
reasonable assumption to have.
Consider this use case: drain the queue on drop by performing
app-specific cleanup of queued messages.
The obvious implementation would be:
```
impl Drop for MyReceiverWrapper {
fn drop(&mut self) {
while let Ok(Some(m)) self.try_next() {
cleanup(m);
}
}
}
```
Without this change, I cannot even say for sure how this code need
to be implemented to avoid panicking. E. g. is `is_closed` enough
or some additional checks need to be performed?1 parent 48d0096 commit 4d2ad0e
2 files changed
+30
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1020 | 1020 | | |
1021 | 1021 | | |
1022 | 1022 | | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | 1023 | | |
1027 | 1024 | | |
1028 | 1025 | | |
| |||
1033 | 1030 | | |
1034 | 1031 | | |
1035 | 1032 | | |
1036 | | - | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | 1039 | | |
| |||
1173 | 1173 | | |
1174 | 1174 | | |
1175 | 1175 | | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
1179 | 1176 | | |
1180 | 1177 | | |
1181 | 1178 | | |
| |||
1186 | 1183 | | |
1187 | 1184 | | |
1188 | 1185 | | |
1189 | | - | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
1190 | 1190 | | |
1191 | 1191 | | |
1192 | 1192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
0 commit comments