Skip to content

Make Condvar::wait_timeout return an enum instead of a bool #27826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 22, 2015

Conversation

sfackler
Copy link
Member

Returning a primitive bool results in a somewhat confusing API - does
true indicate success - i.e. no timeout, or that a timeout has
occurred? An explicitly named enum makes it clearer.

[breaking-change]

r? @alexcrichton

/// A type indicating whether a timed wait on a condition variable returned
/// due to a time out or not.
#[derive(Debug, PartialEq, Eq)]
pub enum TimedOut {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be the best way of representing/naming this enum.

@alexcrichton
Copy link
Member

Perhaps this could also have a convenience boolean accessor method like BarrierWaitResult ?

@alexcrichton
Copy link
Member

This may also want to consider naming with respect to that as well.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Aug 14, 2015
@sfackler
Copy link
Member Author

I'll add a timed_out boolean accessor. Since this type is an enum, people will be writing the name out so it should probably be short-ish.

@sfackler
Copy link
Member Author

Updated with the accessor.

@alexcrichton
Copy link
Member

Hm, so BarrierWaitResult doesn't actually expose an enum, but rather just a boolean accessor. Perhaps that may be the most conservative route? The tuple return value also still seems a little odd to me, but I'm generally still ok with it.

cc @aturon, thoughts on this return value?

@sfackler
Copy link
Member Author

@alexcrichton updated

/// A type indicating whether a timed wait on a condition variable returned
/// due to a time out or not.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[unstable(feature = "wait_timeout", reason = "newly added")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll need an explicit issue tag, and could you also add the unstable tag to the timed_out method?

@alexcrichton
Copy link
Member

r=me with a nit, thanks @sfackler!

Returning a primitive bool results in a somewhat confusing API - does
`true` indicate success - i.e. no timeout, or that a timeout has
occurred? An explicitly named enum makes it clearer.

[breaking-change]
@sfackler
Copy link
Member Author

@bors r=alexcrichton

@bors
Copy link
Collaborator

bors commented Aug 20, 2015

📌 Commit 12216b7 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Aug 21, 2015

⌛ Testing commit 12216b7 with merge 8951c00...

@bors
Copy link
Collaborator

bors commented Aug 21, 2015

💔 Test failed - auto-linux-32-opt

@sfackler
Copy link
Member Author

@bors: retry

@bors
Copy link
Collaborator

bors commented Aug 21, 2015

⌛ Testing commit 12216b7 with merge b5f22dc...

@alexcrichton
Copy link
Member

@bors: retry force

bors added a commit that referenced this pull request Aug 22, 2015
Returning a primitive bool results in a somewhat confusing API - does
`true` indicate success - i.e. no timeout, or that a timeout has
occurred? An explicitly named enum makes it clearer.

[breaking-change]

r? @alexcrichton
@bors
Copy link
Collaborator

bors commented Aug 22, 2015

⌛ Testing commit 12216b7 with merge 983d2b3...

@bors bors merged commit 12216b7 into rust-lang:master Aug 22, 2015
@sfackler sfackler deleted the wait-timeout-enum branch November 26, 2016 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants