Skip to content

Commit

Permalink
use try_recv instead of poll
Browse files Browse the repository at this point in the history
  • Loading branch information
dvic authored and asomers committed Jan 9, 2019
1 parent 04f71d4 commit 627b51a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = ["tokio"]
tokio = ["tokio-current-thread", "tokio-executor"]

[dependencies]
futures = "0.1.20"
futures = "0.1.25"
tokio-current-thread = { version = "0.1.4", optional = true }
tokio-executor = { version = "0.1.5", optional = true }

Expand Down
9 changes: 3 additions & 6 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ impl<T: ?Sized> Drop for MutexFut<T> {
},
&mut FutState::Pending(ref mut rx) => {
rx.close();
// TODO: futures-0.2.0 introduces a try_recv method that is
// better to use here than poll. Use it after upgrading to
// futures >= 0.2.0
match rx.poll() {
Ok(Async::Ready(())) => {
match rx.try_recv() {
Ok(Some(())) => {
// This future received ownership of the mutex, but got
// dropped before it was ever polled. Release the
// mutex.
self.mutex.unlock()
},
Ok(Async::NotReady) => {
Ok(None) => {
// Dropping the Future before it acquires the Mutex is
// equivalent to cancelling it.
},
Expand Down
18 changes: 6 additions & 12 deletions src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,14 @@ impl<T: ?Sized> Drop for RwLockReadFut<T> {
},
&mut FutState::Pending(ref mut rx) => {
rx.close();
// TODO: futures-0.2.0 introduces a try_recv method that is
// better to use here than poll. Use it after upgrading to
// futures >= 0.2.0
match rx.poll() {
Ok(Async::Ready(())) => {
match rx.try_recv() {
Ok(Some(())) => {
// This future received ownership of the lock, but got
// dropped before it was ever polled. Release the
// lock.
self.rwlock.unlock_reader()
},
Ok(Async::NotReady) => {
Ok(None) => {
// Dropping the Future before it acquires the lock is
// equivalent to cancelling it.
},
Expand Down Expand Up @@ -170,17 +167,14 @@ impl<T: ?Sized> Drop for RwLockWriteFut<T> {
},
&mut FutState::Pending(ref mut rx) => {
rx.close();
// TODO: futures-0.2.0 introduces a try_recv method that is
// better to use here than poll. Use it after upgrading to
// futures >= 0.2.0
match rx.poll() {
Ok(Async::Ready(())) => {
match rx.try_recv() {
Ok(Some(())) => {
// This future received ownership of the lock, but got
// dropped before it was ever polled. Release the
// lock.
self.rwlock.unlock_writer()
},
Ok(Async::NotReady) => {
Ok(None) => {
// Dropping the Future before it acquires the lock is
// equivalent to cancelling it.
},
Expand Down

0 comments on commit 627b51a

Please sign in to comment.