Skip to content

Commit 21e3684

Browse files
committed
---
yaml --- r: 15744 b: refs/heads/try c: c6d33c3 h: refs/heads/master v: v3
1 parent b40eacf commit 21e3684

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 13a4b59cc854d9c47d885bd1e468e094d53756b1
5+
refs/heads/try: c6d33c3d37c0e9f8db88b7402da45506d7f44d33
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/comm.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export peek;
3434
export recv_chan;
3535
export select2;
3636
export methods;
37+
export listen;
3738

3839

3940
#[doc = "
@@ -86,6 +87,12 @@ impl methods<T: send> for chan<T> {
8687

8788
}
8889

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+
8996
resource port_ptr<T: send>(po: *rust_port) {
9097
// Once the port is detached it's guaranteed not to receive further
9198
// messages
@@ -441,4 +448,14 @@ fn test_chan_peek() {
441448
let ch = po.chan();
442449
ch.send(());
443450
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+
}
444461
}

0 commit comments

Comments
 (0)