@@ -60,21 +60,17 @@ use uint;
60
60
61
61
macro_rules! select {
62
62
(
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) ,+
65
64
) => ( {
66
65
use std:: comm:: Select ;
67
66
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) ; ) +
70
68
unsafe {
71
- $port1. add( ) ;
72
- $( $port. add( ) ; ) *
69
+ $( $port. add( ) ; ) +
73
70
}
74
71
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!( ) }
78
74
} )
79
75
}
80
76
@@ -94,7 +90,7 @@ pub struct Select {
94
90
pub struct Handle < ' port , T > {
95
91
/// The ID of this handle, used to compare against the return value of
96
92
/// `Select::wait()`
97
- id : uint ,
93
+ priv id: uint ,
98
94
priv selector : & ' port Select ,
99
95
priv next : * mut Handle < ' static , ( ) > ,
100
96
priv prev : * mut Handle < ' static , ( ) > ,
@@ -150,7 +146,7 @@ impl Select {
150
146
151
147
/// Waits for an event on this port set. The returned valus is *not* and
152
148
/// 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
154
150
/// the matching `id` will have some sort of event available on it. The
155
151
/// event could either be that data is available or the corresponding
156
152
/// channel has been closed.
@@ -242,6 +238,10 @@ impl Select {
242
238
}
243
239
244
240
impl < ' port , T : Send > Handle < ' port , T > {
241
+ /// Retrieve the id of this handle.
242
+ #[ inline]
243
+ pub fn id ( & self ) -> uint { self . id }
244
+
245
245
/// Receive a value on the underlying port. Has the same semantics as
246
246
/// `Port.recv`
247
247
pub fn recv ( & mut self ) -> T { self . port . recv ( ) }
@@ -355,7 +355,7 @@ mod test {
355
355
)
356
356
drop( c2) ;
357
357
select! (
358
- bar = p2. recv_opt( ) => { assert_eq!( bar, None ) ; } ,
358
+ bar = p2. recv_opt( ) => { assert_eq!( bar, None ) ; }
359
359
)
360
360
} )
361
361
0 commit comments