@@ -60,21 +60,17 @@ use uint;
6060
6161macro_rules! select {
6262 (
63- $name1: pat = $port1: ident. $meth1: ident( ) => $code1: expr,
64- $( $name: pat = $port: ident. $meth: ident( ) => $code: expr) ,*
63+ $( $name: pat = $port: ident. $meth: ident( ) => $code: expr) ,+
6564 ) => ( {
6665 use std:: comm:: Select ;
6766 let sel = Select :: new( ) ;
68- let mut $port1 = sel. handle( & $port1) ;
69- $( let mut $port = sel. handle( & $port) ; ) *
67+ $( let mut $port = sel. handle( & $port) ; ) +
7068 unsafe {
71- $port1. add( ) ;
72- $( $port. add( ) ; ) *
69+ $( $port. add( ) ; ) +
7370 }
7471 let ret = sel. wait( ) ;
75- if ret == $port1. id { let $name1 = $port1. $meth1( ) ; $code1 }
76- $( else if ret == $port. id { let $name = $port. $meth( ) ; $code } ) *
77- else { unreachable!( ) }
72+ $( if ret == $port. id( ) { let $name = $port. $meth( ) ; $code } else ) +
73+ { unreachable!( ) }
7874 } )
7975}
8076
@@ -94,7 +90,7 @@ pub struct Select {
9490pub struct Handle < ' port , T > {
9591 /// The ID of this handle, used to compare against the return value of
9692 /// `Select::wait()`
97- id : uint ,
93+ priv id: uint ,
9894 priv selector : & ' port Select ,
9995 priv next : * mut Handle < ' static , ( ) > ,
10096 priv prev : * mut Handle < ' static , ( ) > ,
@@ -150,7 +146,7 @@ impl Select {
150146
151147 /// Waits for an event on this port set. The returned valus is *not* and
152148 /// index, but rather an id. This id can be queried against any active
153- /// `Handle` structures (each one has a public `id` field ). The handle with
149+ /// `Handle` structures (each one has an `id` method ). The handle with
154150 /// the matching `id` will have some sort of event available on it. The
155151 /// event could either be that data is available or the corresponding
156152 /// channel has been closed.
@@ -242,6 +238,10 @@ impl Select {
242238}
243239
244240impl < ' port , T : Send > Handle < ' port , T > {
241+ /// Retrieve the id of this handle.
242+ #[ inline]
243+ pub fn id ( & self ) -> uint { self . id }
244+
245245 /// Receive a value on the underlying port. Has the same semantics as
246246 /// `Port.recv`
247247 pub fn recv ( & mut self ) -> T { self . port . recv ( ) }
@@ -355,7 +355,7 @@ mod test {
355355 )
356356 drop( c2) ;
357357 select! (
358- bar = p2. recv_opt( ) => { assert_eq!( bar, None ) ; } ,
358+ bar = p2. recv_opt( ) => { assert_eq!( bar, None ) ; }
359359 )
360360 } )
361361
0 commit comments