@@ -14,7 +14,7 @@ use async_task::{Runnable, Task};
1414use crossbeam_deque:: { Injector , Steal , Stealer , Worker } ;
1515use crossbeam_utils:: sync:: { Parker , Unparker } ;
1616
17- use crate :: { Context , ContextId , io :: Io , mux:: Mux } ;
17+ use crate :: { Context , ContextId , mux:: Mux } ;
1818
1919/// A work-stealing async executor.
2020#[ derive( Debug ) ]
@@ -251,20 +251,6 @@ impl Executor {
251251 ExecutorBuilder :: default ( )
252252 }
253253
254- /// Spawns a new task on the executor.
255- pub fn spawn < F > ( & self , future : F ) -> Task < F :: Output >
256- where
257- F : std:: future:: Future + Send + ' static ,
258- F :: Output : Send + ' static ,
259- {
260- spawn_on ( & self . inner , future)
261- }
262-
263- /// Opens an I/O channel for the given context ID.
264- pub fn open_io ( & self , id : & [ u8 ] ) -> Result < Io , std:: io:: Error > {
265- self . inner . mux . open ( id)
266- }
267-
268254 /// Shuts down the executor.
269255 pub fn shutdown ( & self ) {
270256 self . inner . shutdown . store ( true , Ordering :: SeqCst ) ;
@@ -342,10 +328,14 @@ mod tests {
342328 let ( mux_a, _mux_b) = test_framed_mux ( 1024 ) ;
343329 let executor = Executor :: builder ( ) . num_threads ( 2 ) . build ( mux_a) ;
344330
345- let task = executor. spawn ( async { 42 } ) ;
346- let result = futures:: executor:: block_on ( task) ;
331+ let mut ctx = executor. new_context ( ) . unwrap ( ) ;
332+ let ( a, b) = futures:: executor:: block_on ( ctx. join (
333+ |_ctx| Box :: pin ( async move { 21 } ) ,
334+ |_ctx| Box :: pin ( async move { 21 } ) ,
335+ ) )
336+ . unwrap ( ) ;
347337
348- assert_eq ! ( result , 42 ) ;
338+ assert_eq ! ( a + b , 42 ) ;
349339
350340 executor. shutdown ( ) ;
351341 }
@@ -391,29 +381,20 @@ mod tests {
391381 let executor_a = Executor :: builder ( ) . num_threads ( 2 ) . build ( mux_a) ;
392382 let executor_b = Executor :: builder ( ) . num_threads ( 2 ) . build ( mux_b) ;
393383
394- // Party A sends, Party B receives.
395- let task_a = {
396- let id = ContextId :: new ( 1 ) ;
397- let mut io = executor_a. open_io ( id. as_ref ( ) ) . unwrap ( ) ;
398-
399- executor_a. spawn ( async move {
400- io. send ( 42u32 ) . await . unwrap ( ) ;
401- io. send ( 123u32 ) . await . unwrap ( ) ;
402- } )
403- } ;
404-
405- let task_b = {
406- let id = ContextId :: new ( 1 ) ;
407- let mut io = executor_b. open_io ( id. as_ref ( ) ) . unwrap ( ) ;
384+ let mut ctx_a = executor_a. new_context ( ) . unwrap ( ) ;
385+ let mut ctx_b = executor_b. new_context ( ) . unwrap ( ) ;
408386
409- executor_b. spawn ( async move {
410- let val1: u32 = io. next ( ) . await . unwrap ( ) . unwrap ( ) ;
411- let val2: u32 = io. next ( ) . await . unwrap ( ) . unwrap ( ) ;
387+ let ( _, ( val1, val2) ) = futures:: executor:: block_on ( futures:: future:: join (
388+ async {
389+ ctx_a. io_mut ( ) . send ( 42u32 ) . await . unwrap ( ) ;
390+ ctx_a. io_mut ( ) . send ( 123u32 ) . await . unwrap ( ) ;
391+ } ,
392+ async {
393+ let val1: u32 = ctx_b. io_mut ( ) . next ( ) . await . unwrap ( ) . unwrap ( ) ;
394+ let val2: u32 = ctx_b. io_mut ( ) . next ( ) . await . unwrap ( ) . unwrap ( ) ;
412395 ( val1, val2)
413- } )
414- } ;
415-
416- let ( ( ) , ( val1, val2) ) = futures:: executor:: block_on ( futures:: future:: join ( task_a, task_b) ) ;
396+ } ,
397+ ) ) ;
417398
418399 assert_eq ! ( val1, 42 ) ;
419400 assert_eq ! ( val2, 123 ) ;
0 commit comments