@@ -41,27 +41,9 @@ closed, causing a failure otherwise. This should not be sent/used from
41
41
42
42
#[ doc = "
43
43
Useful for anyone who wants to roll their own `high_level_loop`.
44
-
45
- # Arguments
46
-
47
- * loop_ptr - a pointer to a currently unused libuv loop. Its `data` field
48
- will be overwritten before the loop begins
49
- * msg_po - an active port that receives `high_level_msg`s. You can distribute
50
- a paired channel to users, along with the `async_handle` returned in the
51
- following callback (combine them to make a `hl::simpler_task_loop` varient
52
- of `hl::high_level_loop`)
53
- * before_run - a unique closure that is invoked before `uv_run()` is called
54
- on the provided `loop_ptr`. An `async_handle` is passed in which will be
55
- live for the duration of the loop. You can distribute this to users so that
56
- they can interact with the loop safely.
57
- * before_msg_process - a unique closure that is invoked at least once when
58
- the loop is woken up, and once more for every message that is drained from
59
- the loop's msg port
60
- * before_tear_down - called just before the loop invokes `uv_close()` on the
61
- provided `async_handle`. `uv_run` should return shortly after
62
44
" ]
63
- unsafe fn run_high_level_loop ( msg_po : port < high_level_msg > ,
64
- before_run : fn ~ ( * ll :: uv_async_t ) ) {
45
+ unsafe fn run_high_level_loop ( hll_ch : chan < high_level_loop > ) {
46
+ let msg_po = port :: < high_level_msg > ( ) ;
65
47
let loop_ptr = ll:: loop_new ( ) ;
66
48
// set up the special async handle we'll use to allow multi-task
67
49
// communication with this loop
@@ -78,8 +60,13 @@ unsafe fn run_high_level_loop(msg_po: port<high_level_msg>,
78
60
} ;
79
61
ll:: set_data_for_uv_handle ( async_handle, addr_of ( data) ) ;
80
62
81
- // call before_run
82
- before_run ( async_handle) ;
63
+ // Send out a handle through which folks can talk to us
64
+ // while we dwell in the I/O loop
65
+ let hll = high_level_loop ( {
66
+ async_handle: async_handle,
67
+ op_chan: msg_po. chan ( )
68
+ } ) ;
69
+ hll_ch. send ( hll) ;
83
70
84
71
log ( debug, "about to run high level loop" ) ;
85
72
// enter the loop... this blocks until the loop is done..
@@ -224,19 +211,8 @@ mod test {
224
211
let hl_loop_port = comm:: port :: < high_level_loop > ( ) ;
225
212
let hl_loop_ch = comm:: chan ( hl_loop_port) ;
226
213
task:: spawn_sched ( task:: manual_threads ( 1 u) ) { ||
227
- let msg_po = comm:: port :: < high_level_msg > ( ) ;
228
- let msg_ch = comm:: chan ( msg_po) ;
229
- run_high_level_loop ( msg_po) { |async_handle|
230
- log ( debug, #fmt ( "hltest before_run: async_handle %?" ,
231
- async_handle) ) ;
232
- // do an async_send with it
233
- ll:: async_send ( async_handle) ;
234
- comm:: send ( hl_loop_ch, high_level_loop ( {
235
- async_handle: async_handle,
236
- op_chan: msg_ch
237
- } ) ) ;
238
- }
239
- comm:: send ( exit_ch, ( ) ) ;
214
+ run_high_level_loop ( hl_loop_ch) ;
215
+ exit_ch. send ( ( ) ) ;
240
216
} ;
241
217
ret comm:: recv ( hl_loop_port) ;
242
218
}
0 commit comments