Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAPI convention for blocking-, timeout-, and/or deadline-related functions #46316
Comments
ia0
added a commit
to ia0/rust
that referenced
this issue
Nov 27, 2017
kennytm
added
C-feature-request
T-libs
labels
Nov 27, 2017
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton, as requested in #45969, I'm cc-ing you here to discuss which API we want for deadline-related functions. |
This comment has been minimized.
This comment has been minimized.
|
parking-lot uses |
This comment has been minimized.
This comment has been minimized.
|
Thanks @sfackler for the parking-lot example. This example actually conflicts with the standard library versions and extends the "no meaningful blocking version" suggestion above to functions that actually have a blocking version. If I reformulate the suggestion according to this information, it would be:
These rules overlap which is unfortunate, but this is maybe the freedom we need to account for the current state of naming by interpreting the primary role of a function differently. For example, for the standard library, the main role of Just to clarify, with the current suggestion (and the first one which was very similar), Here is the current suggestion (and whether it differs from the current state):
|
This comment has been minimized.
This comment has been minimized.
|
I took the time to go over the existing crates by downloading the latest version of each crate and grepping for public functions taking an
I changed the terminology for timeout and deadline versions to duration and instant versions to reflect the types and avoid possible biaises. Here are some examples according to the 4 versions (blocking, non-blocking, duration, and instant):
Using
We see some usage of
Some outsiders:
|
alexcrichton
added
B-unstable
and removed
C-feature-request
labels
Dec 1, 2017
This comment has been minimized.
This comment has been minimized.
|
It's worth pointing out that there may also just not be a convention to be had here. There's certainly not an "obvious agreement" amongst everything today it seems like and I wouldn't want to bend over too much to try to fit things in! That being said I do sort of like the |
spastorino
added a commit
to spastorino/rust
that referenced
this issue
Dec 5, 2017
XAMPPRocky
added
C-enhancement
T-lang
and removed
T-lang
labels
Feb 19, 2018
This comment has been minimized.
This comment has been minimized.
|
This thread suggests renaming This issue is now also the tracking issue for |
This comment has been minimized.
This comment has been minimized.
|
I created this issue in response to #45969 (comment). Maybe we should split it between the tracking issue of What is the timeline for a tracking issue? Should we keep it open until the feature goes stable? Is there any time constraints about this? |
This comment has been minimized.
This comment has been minimized.
|
There is no time constraint. A tracking issue stays open until the corresponding feature becomes stable (in the sense of: does not require |
ia0 commentedNov 27, 2017
The standard library currently exposes several blocking- and/or timeout-related functions:
std::sync::Condvar::wait*waitwait_timeout_mswait_timeoutstd::sync::mpsc::Receiver::recv*recvrecv_timeoutstd::thread::park*parkpark_timeout_mspark_timeoutstd::thread::sleep*sleep_mssleepThe timeout versions taking a
u32in milliseconds are actually deprecated for the version taking aDurationsince1.6.0.This issue tracks the possibility to extend these APIs and provide a convention for blocking-, timeout-, and/or deadline-related functions. The current suggestion is:
std::sync::Condvar::wait*waitwait_timeoutwait_deadlinestd::sync::mpsc::Receiver::recv*recvrecv_timeoutrecv_deadlinestd::thread::park*parkpark_timeoutpark_deadlinestd::thread::sleep*sleep_forsleep_untilThe blocking versions do not take any extra argument and are not suffixed. The timeout versions take a timeout as a
Durationand return if this timeout is reached (the timeout starts when the function is called with best-effort precision). They are suffixed by_timeout. The deadline versions take a deadline as anInstantand return if this deadline is reached (the deadline precision is best-effort). They are suffixed by_deadline.For functions that do not have a meaningful blocking version (like sleep which would essentially block until the program ends), the timeout version would be suffixed by
_forand the deadline version would be suffixed by_until. We don't have enough data-points to see if this rule is actually applicable. In a first iteration, we could leave aside those functions that do not have a meaningful blocking version.