@@ -141,52 +141,46 @@ impl Display for Cancelled {
141141
142142#[ cfg( test) ]
143143mod tests {
144- use futures_channel :: oneshot ;
144+ use std :: time :: Duration ;
145145
146146 use super :: { Cancellable , CancellableFuture , Cancelled } ;
147- use crate :: prelude:: * ;
147+ use crate :: { prelude:: * , spawn_blocking } ;
148148
149149 #[ test]
150150 fn cancellable_future_ok ( ) {
151151 let ctx = glib:: MainContext :: new ( ) ;
152152 let c = Cancellable :: new ( ) ;
153- let ( tx, rx) = oneshot:: channel ( ) ;
154153
155- {
154+ let future = {
156155 ctx. spawn_local ( async {
157156 let cancellable_future = CancellableFuture :: new ( async { 42 } , c) ;
158157 assert ! ( !cancellable_future. is_cancelled( ) ) ;
159158
160159 let result = cancellable_future. await ;
161160 assert ! ( matches!( result, Ok ( 42 ) ) ) ;
161+ } )
162+ } ;
162163
163- tx. send ( ( ) ) . unwrap ( ) ;
164- } ) ;
165- }
166-
167- ctx. block_on ( rx) . unwrap ( )
164+ ctx. block_on ( future) . unwrap ( )
168165 }
169166
170167 #[ test]
171168 fn cancellable_future_cancel ( ) {
172169 let ctx = glib:: MainContext :: new ( ) ;
173170 let c = Cancellable :: new ( ) ;
174- let ( tx, rx) = oneshot:: channel ( ) ;
175171
176- {
172+ let future = {
177173 let c = c. clone ( ) ;
178174 ctx. spawn_local ( async move {
179175 let cancellable_future = CancellableFuture :: new ( std:: future:: pending :: < ( ) > ( ) , c) ;
180176
181177 let result = cancellable_future. await ;
182178 assert ! ( matches!( result, Err ( Cancelled ) ) ) ;
183-
184- tx. send ( ( ) ) . unwrap ( ) ;
185- } ) ;
186- }
179+ } )
180+ } ;
187181
188182 std:: thread:: spawn ( move || c. cancel ( ) ) . join ( ) . unwrap ( ) ;
189183
190- ctx. block_on ( rx ) . unwrap ( ) ;
184+ ctx. block_on ( future ) . unwrap ( ) ;
191185 }
192186}
0 commit comments