@@ -2,11 +2,11 @@ use std::{
2
2
future:: Future ,
3
3
mem,
4
4
pin:: Pin ,
5
- sync:: { Arc , Condvar , Mutex } ,
5
+ sync:: Arc ,
6
6
task:: { Context , Poll , Waker } ,
7
7
} ;
8
8
9
- // FIXME: use locking primitives from ` crate::sync`
9
+ use crate :: sync:: { Condvar , Mutex } ;
10
10
11
11
/// Creates a connected pair of [`Promise`] and [`PromiseHandle`].
12
12
#[ doc( alias = "oneshot" ) ]
@@ -51,7 +51,7 @@ impl<T> Drop for Promise<T> {
51
51
return ;
52
52
}
53
53
54
- * self . inner . state . lock ( ) . unwrap ( ) = PromiseState :: Dropped ;
54
+ * self . inner . state . lock ( ) = PromiseState :: Dropped ;
55
55
self . inner . condvar . notify_one ( ) ;
56
56
}
57
57
}
@@ -68,7 +68,7 @@ impl<T> Promise<T> {
68
68
// This ignores errors. The assumption is that the thread will exit once it tries to obtain
69
69
// a new `Promise` to fulfill.
70
70
self . fulfilled = true ;
71
- let mut guard = self . inner . state . lock ( ) . unwrap ( ) ;
71
+ let mut guard = self . inner . state . lock ( ) ;
72
72
let wakers = match & mut * guard {
73
73
PromiseState :: Empty ( wakers) => mem:: take ( wakers) ,
74
74
_ => unreachable ! ( ) ,
@@ -103,10 +103,10 @@ impl<T> PromiseHandle<T> {
103
103
///
104
104
/// [`Worker`]: crate::Worker
105
105
pub fn block ( self ) -> Result < T , PromiseDropped > {
106
- let mut state = self . inner . state . lock ( ) . unwrap ( ) ;
106
+ let mut state = self . inner . state . lock ( ) ;
107
107
loop {
108
108
match * state {
109
- PromiseState :: Empty ( _) => state = self . inner . condvar . wait ( state) . unwrap ( ) ,
109
+ PromiseState :: Empty ( _) => state = self . inner . condvar . wait ( state) ,
110
110
PromiseState :: Fulfilled ( _) => {
111
111
let fulfilled = mem:: replace ( & mut * state, PromiseState :: Dropped ) ;
112
112
match fulfilled {
@@ -130,7 +130,7 @@ impl<T> PromiseHandle<T> {
130
130
impl < T > Future for Waiter < T > {
131
131
type Output = Result < T , PromiseDropped > ;
132
132
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
133
- let mut state = self . 0 . inner . state . lock ( ) . unwrap ( ) ;
133
+ let mut state = self . 0 . inner . state . lock ( ) ;
134
134
match & mut * state {
135
135
PromiseState :: Empty ( wakers) => {
136
136
wakers. push ( cx. waker ( ) . clone ( ) ) ;
0 commit comments