@@ -56,20 +56,6 @@ pub trait Peekable<T> {
56
56
fn peek ( & self ) -> bool ;
57
57
}
58
58
59
- /// Returns the index of an endpoint that is ready to receive.
60
- pub fn selecti < T : Selectable > ( endpoints : & [ T ] ) -> uint {
61
- wait_many ( endpoints)
62
- }
63
-
64
- /// Returns 0 or 1 depending on which endpoint is ready to receive
65
- pub fn select2i < A : Selectable , B : Selectable > ( a : & A , b : & B ) ->
66
- Either < ( ) , ( ) > {
67
- match wait_many ( [ a. header ( ) , b. header ( ) ] ) {
68
- 0 => Left ( ( ) ) ,
69
- 1 => Right ( ( ) ) ,
70
- _ => fail ! ( ~"wait returned unexpected index")
71
- }
72
- }
73
59
74
60
// Streams - Make pipes a little easier in general.
75
61
@@ -322,38 +308,6 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
322
308
unstable::exclusive(c)
323
309
}
324
310
325
- /// Receive a message from one of two endpoints.
326
- pub trait Select2<T: Owned, U: Owned> {
327
- /// Receive a message or return `None` if a connection closes.
328
- fn try_select(&self) -> Either<Option<T>, Option<U>>;
329
- /// Receive a message or fail if a connection closes.
330
- fn select(&self) -> Either<T, U>;
331
- }
332
-
333
- impl<T: Owned, U: Owned,
334
- Left: Selectable + GenericPort<T>,
335
- Right: Selectable + GenericPort<U>>
336
- Select2<T, U> for (Left, Right) {
337
-
338
- fn select(&self) -> Either<T, U> {
339
- match *self {
340
- (ref lp, ref rp) => match select2i(lp, rp) {
341
- Left(()) => Left (lp.recv()),
342
- Right(()) => Right(rp.recv())
343
- }
344
- }
345
- }
346
-
347
- fn try_select(&self) -> Either<Option<T>, Option<U>> {
348
- match *self {
349
- (ref lp, ref rp) => match select2i(lp, rp) {
350
- Left(()) => Left (lp.try_recv()),
351
- Right(()) => Right(rp.try_recv())
352
- }
353
- }
354
- }
355
- }
356
-
357
311
/*proto! oneshot (
358
312
Oneshot:send<T:Owned> {
359
313
send(T) -> !
@@ -486,6 +440,55 @@ pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
486
440
oneshot::client::try_send(chan, data).is_some()
487
441
}
488
442
443
+
444
+
445
+ /// Returns the index of an endpoint that is ready to receive.
446
+ pub fn selecti<T: Selectable>(endpoints: &[T]) -> uint {
447
+ wait_many(endpoints)
448
+ }
449
+
450
+ /// Returns 0 or 1 depending on which endpoint is ready to receive
451
+ pub fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) ->
452
+ Either<(), ()> {
453
+ match wait_many([a.header(), b.header()]) {
454
+ 0 => Left(()),
455
+ 1 => Right(()),
456
+ _ => fail!(~" wait returned unexpected index")
457
+ }
458
+ }
459
+
460
+ /// Receive a message from one of two endpoints.
461
+ pub trait Select2<T: Owned, U: Owned> {
462
+ /// Receive a message or return `None` if a connection closes.
463
+ fn try_select(&self) -> Either<Option<T>, Option<U>>;
464
+ /// Receive a message or fail if a connection closes.
465
+ fn select(&self) -> Either<T, U>;
466
+ }
467
+
468
+ impl<T: Owned, U: Owned,
469
+ Left: Selectable + GenericPort<T>,
470
+ Right: Selectable + GenericPort<U>>
471
+ Select2<T, U> for (Left, Right) {
472
+
473
+ fn select(&self) -> Either<T, U> {
474
+ match *self {
475
+ (ref lp, ref rp) => match select2i(lp, rp) {
476
+ Left(()) => Left (lp.recv()),
477
+ Right(()) => Right(rp.recv())
478
+ }
479
+ }
480
+ }
481
+
482
+ fn try_select(&self) -> Either<Option<T>, Option<U>> {
483
+ match *self {
484
+ (ref lp, ref rp) => match select2i(lp, rp) {
485
+ Left(()) => Left (lp.try_recv()),
486
+ Right(()) => Right(rp.try_recv())
487
+ }
488
+ }
489
+ }
490
+ }
491
+
489
492
#[cfg(test)]
490
493
mod test {
491
494
use either::Right;
0 commit comments