feat(blocking::mpsc): add Receiver::recv(_ref)_timeout methods#75
feat(blocking::mpsc): add Receiver::recv(_ref)_timeout methods#75hawkw merged 5 commits intohawkw:mainfrom
Receiver::recv(_ref)_timeout methods#75Conversation
|
@hawkw Any chance of getting this merged? |
|
@utkarshgupta137 whoops, sorry, this one slipped past me. Let me take a look! |
hawkw
left a comment
There was a problem hiding this comment.
Overall, this looks good to me! I had some suggestions for potentially changing the documentation to be closer to the documentation for other methods in this module.
Co-authored-by: Eliza Weisman <[email protected]>
hawkw
left a comment
There was a problem hiding this comment.
oops i messed up some of the docs suggestions a little
|
@utkarshgupta137 thanks for the PR, happy to merge it once CI passes! are you interested in adding Also, we should probably update the README to no longer state that Lines 76 to 79 in a0e5740 |
Head branch was pushed to by a user without write access
|
It looks like the Let's add |
Sure, I'll try to add them, but let's release this first since I actually need these :) |
|
Sweet! Looking forward to a new release. |
|
Hmm, it looks like the doctests that were added in this PR are not deterministic --- they sometimes fail spuriously (presumably based on OS scheduler behavior): https://github.com/hawkw/thingbuf/actions/runs/4813223393/jobs/8569477594#step:4:194 Can we fix this? I'd prefer to have examples that don't involve multiple threads being scheduled in the right order --- perhaps we can base our examples on |
I think just increasing the durations would fix the issue?
Do you mean creating 2 different examples? |
Yes, the other thing I would note is that the standard library's examples never actually spawn an additional thread. Instead, it demonstrates the timeout behavior by trying to receive from a channel that will never have a message sent to it. I would kind of prefer to write our examples this way, because it's more deterministic and the doctests should never spuriously fail depending on scheduler behavior. |
But they're spawning additional threads & depending on the scheduler behavior... Success thread::spawn(move || {
send.send('a').unwrap();
});
assert_eq!(
recv.recv_timeout(Duration::from_millis(400)),
Ok('a')
);Failure: thread::spawn(move || {
thread::sleep(Duration::from_millis(800));
send.send('a').unwrap();
});
assert_eq!(
recv.recv_timeout(Duration::from_millis(400)),
Err(mpsc::RecvTimeoutError::Timeout)
); |
...yup, you're right, I can't read, apparently. I think increasing the sleep duration to at least twice the timeout is probably sufficient, then! |
Follow up to #75. Co-authored-by: Eliza Weisman <[email protected]>
Added recv_timeout methods for blocking::mpsc::Receiver/StaticReceiver. It requires a simple change from
thread::parktothread::park_timeout& an elapsed time check.We need this functionality so that our threads can wake up at least once every few seconds to check for control events