File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
- refs/heads/try: 13a4b59cc854d9c47d885bd1e468e094d53756b1
5
+ refs/heads/try: c6d33c3d37c0e9f8db88b7402da45506d7f44d33
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ export peek;
34
34
export recv_chan;
35
35
export select2;
36
36
export methods;
37
+ export listen;
37
38
38
39
39
40
#[ doc = "
@@ -86,6 +87,12 @@ impl methods<T: send> for chan<T> {
86
87
87
88
}
88
89
90
+ #[ doc = "Open a new receiving channel for the duration of a function" ]
91
+ fn listen < T : send , U > ( f : fn ( chan < T > ) -> U ) -> U {
92
+ let po = port ( ) ;
93
+ f ( po. chan ( ) )
94
+ }
95
+
89
96
resource port_ptr<T : send>( po: * rust_port) {
90
97
// Once the port is detached it's guaranteed not to receive further
91
98
// messages
@@ -441,4 +448,14 @@ fn test_chan_peek() {
441
448
let ch = po. chan ( ) ;
442
449
ch. send ( ( ) ) ;
443
450
assert ch. peek ( ) ;
451
+ }
452
+
453
+ #[ test]
454
+ fn test_listen ( ) {
455
+ listen { |parent|
456
+ task:: spawn { ||
457
+ parent. send ( "oatmeal-salad" ) ;
458
+ }
459
+ assert parent. recv ( ) == "oatmeal-salad" ;
460
+ }
444
461
}
You can’t perform that action at this time.
0 commit comments