Replies: 1 comment 3 replies
-
Well, if loop {
if cancel.try_recv() != Err(TryRecvError::Empty) { break; }
let data = redis.xread_options::<_, _, StreamReadReply>(mwi, &now, &opts);
if cancel.try_recv() != Err(TryRecvError::Empty) { break; }
...
} Of course this way the cancellation does not take effect immediately, but if Redis doesn't support that, there isn't much you can do about it. One variant would be to do something like this: loop {
if cancel.try_recv() != Err(TryRecvError::Empty) { break; }
let data = tokio::select! {
data = redis.xread_options::<_, _, StreamReadReply>(mwi, &now, &opts) => data,
_ = async { (&mut cancel).await; sleep(Duration::from_millis(500)).await; } => break,
};
if cancel.try_recv() != Err(TryRecvError::Empty) { break; }
...
} Then we only cancel it if it has stalled for 500 ms. You would just close the connection if it gets cancelled during the operation. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Greetings!
I have some problem with task cancellation. So, example:
When I send
tx.send(()).await;
, yeah, loop are breaking. But, future withredis.xread_options
(from what I read) just suspends without releasing data. So, as result, I got dangling connection to Redis DB.P.S. I'm using redis from here: https://github.com/mitsuhiko/redis-rs
Beta Was this translation helpful? Give feedback.
All reactions