@@ -424,7 +424,7 @@ there is no way to "catch" the exception.
424
424
All tasks are, by default, _ linked_ to each other. That means that the fates
425
425
of all tasks are intertwined: if one fails, so do all the others.
426
426
427
- ~~~
427
+ ~~~ {.xfail-test .linked-failure}
428
428
# use std::task::spawn;
429
429
# use std::task;
430
430
# fn do_some_work() { loop { task::yield() } }
@@ -447,7 +447,7 @@ pattern-match on a result to check whether it's an `Ok` result with an `int`
447
447
field (representing a successful result) or an ` Err ` result (representing
448
448
termination with an error).
449
449
450
- ~~~
450
+ ~~~ {.xfail-test .linked-failure}
451
451
# use std::task;
452
452
# fn some_condition() -> bool { false }
453
453
# fn calculate_result() -> int { 0 }
@@ -490,9 +490,10 @@ proceed). Hence, you will need different _linked failure modes_.
490
490
By default, task failure is _ bidirectionally linked_ , which means that if
491
491
either task fails, it kills the other one.
492
492
493
- ~~~
493
+ ~~~ {.xfail-test .linked-failure}
494
494
# use std::task;
495
- # fn sleep_forever() { loop { task::yield() } }
495
+ # use std::comm::oneshot;
496
+ # fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
496
497
# do task::try {
497
498
do spawn {
498
499
do spawn {
@@ -511,11 +512,12 @@ function `task::try`, which we saw previously, uses `spawn_supervised`
511
512
internally, with additional logic to wait for the child task to finish
512
513
before returning. Hence:
513
514
514
- ~~~
515
+ ~~~ {.xfail-test .linked-failure}
515
516
# use std::comm::{stream, Chan, Port};
517
+ # use std::comm::oneshot;
516
518
# use std::task::{spawn, try};
517
519
# use std::task;
518
- # fn sleep_forever() { loop { task::yield() } }
520
+ # fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
519
521
# do task::try {
520
522
let (receiver, sender): (Port<int>, Chan<int>) = stream();
521
523
do spawn { // Bidirectionally linked
@@ -541,9 +543,10 @@ also fail.
541
543
Supervised task failure propagates across multiple generations even if
542
544
an intermediate generation has already exited:
543
545
544
- ~~~
546
+ ~~~ {.xfail-test .linked-failure}
545
547
# use std::task;
546
- # fn sleep_forever() { loop { task::yield() } }
548
+ # use std::comm::oneshot;
549
+ # fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
547
550
# fn wait_for_a_while() { for _ in range(0, 1000u) { task::yield() } }
548
551
# do task::try::<int> {
549
552
do task::spawn_supervised {
@@ -560,7 +563,7 @@ fail!(); // Will kill grandchild even if child has already exited
560
563
Finally, tasks can be configured to not propagate failure to each
561
564
other at all, using ` task::spawn_unlinked ` for _ isolated failure_ .
562
565
563
- ~~~
566
+ ~~~ {.xfail-test .linked-failure}
564
567
# use std::task;
565
568
# fn random() -> uint { 100 }
566
569
# fn sleep_for(i: uint) { for _ in range(0, i) { task::yield() } }
@@ -588,7 +591,7 @@ that repeatedly receives a `uint` message, converts it to a string, and sends
588
591
the string in response. The child terminates when it receives ` 0 ` .
589
592
Here is the function that implements the child task:
590
593
591
- ~~~~
594
+ ~~~ {.xfail-test .linked-failure}
592
595
# use extra::comm::DuplexStream;
593
596
# use std::uint;
594
597
fn stringifier(channel: &DuplexStream<~str, uint>) {
@@ -611,7 +614,7 @@ response itself is simply the stringified version of the received value,
611
614
612
615
Here is the code for the parent task:
613
616
614
- ~~~~
617
+ ~~~{.xfail-test .linked-failure}
615
618
# use std::task::spawn;
616
619
# use std::uint;
617
620
# use extra::comm::DuplexStream;
0 commit comments