@@ -315,34 +315,16 @@ fn done(future: &PyAny) -> PyResult<bool> {
315
315
}
316
316
317
317
#[ pyclass]
318
- struct CheckedSetResult ( ) ;
318
+ struct CheckedCompletor ;
319
319
320
320
#[ pymethods]
321
- impl CheckedSetResult {
322
- fn __call__ ( & self , future : & PyAny , value : PyObject ) -> PyResult < ( ) > {
321
+ impl CheckedCompletor {
322
+ fn __call__ ( & self , future : & PyAny , complete : & PyAny , value : & PyAny ) -> PyResult < ( ) > {
323
323
if done ( future) ? {
324
324
return Ok ( ( ) ) ;
325
325
}
326
326
327
- let set_result = future. getattr ( "set_result" ) ?;
328
- set_result. call1 ( ( value, ) ) ?;
329
-
330
- Ok ( ( ) )
331
- }
332
- }
333
-
334
- #[ pyclass]
335
- struct CheckedSetException ( ) ;
336
-
337
- #[ pymethods]
338
- impl CheckedSetException {
339
- fn __call__ ( & self , future : & PyAny , exception : PyObject ) -> PyResult < ( ) > {
340
- if done ( future) ? {
341
- return Ok ( ( ) ) ;
342
- }
343
-
344
- let set_exception = future. getattr ( "set_exception" ) ?;
345
- set_exception. call1 ( ( exception, ) ) ?;
327
+ complete. call1 ( ( value, ) ) ?;
346
328
347
329
Ok ( ( ) )
348
330
}
@@ -352,13 +334,11 @@ fn set_result(event_loop: &PyAny, future: &PyAny, result: PyResult<PyObject>) ->
352
334
let py = event_loop. py ( ) ;
353
335
let none = py. None ( ) . into_ref ( py) ;
354
336
355
- let checked_set_result = CheckedSetResult ( ) . into_py ( py) . into_ref ( py) ;
356
- let checked_set_exception = CheckedSetException ( ) . into_py ( py) . into_ref ( py) ;
357
-
358
- match result {
359
- Ok ( val) => call_soon_threadsafe ( event_loop, none, ( checked_set_result, future, val) ) ?,
360
- Err ( err) => call_soon_threadsafe ( event_loop, none, ( checked_set_exception, future, err) ) ?,
361
- }
337
+ let ( complete, val) = match result {
338
+ Ok ( val) => ( future. getattr ( "set_result" ) ?, val. into_py ( py) ) ,
339
+ Err ( err) => ( future. getattr ( "set_exception" ) ?, err. into_py ( py) ) ,
340
+ } ;
341
+ call_soon_threadsafe ( event_loop, none, ( CheckedCompletor , future, complete, val) ) ?;
362
342
363
343
Ok ( ( ) )
364
344
}
0 commit comments