Skip to content

Commit d2c67ea

Browse files
committed
---
yaml --- r: 23111 b: refs/heads/master c: 6a10e3a h: refs/heads/master i: 23109: c4d2401 23107: 3e9df2b 23103: ab9e21c v: v3
1 parent 15738b8 commit d2c67ea

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 812db1ec0d97217414b4e49962e8da75761b9279
2+
refs/heads/master: 6a10e3a71324cddce3e4dcb21f1b43dcdec89775
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/pipes.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export send_packet, recv_packet, send, recv, try_recv, peek;
7676
export select, select2, selecti, select2i, selectable;
7777
export spawn_service, spawn_service_recv;
7878
export stream, port, chan, shared_chan, port_set, channel;
79+
export oneshot, recv_one, try_recv_one;
7980

8081
#[doc(hidden)]
8182
const SPIN_COUNT: uint = 0;
@@ -1103,6 +1104,32 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>>
11031104
}
11041105
}
11051106

1107+
proto! oneshot {
1108+
oneshot:send<T:send> {
1109+
send(T) -> !
1110+
}
1111+
}
1112+
1113+
/// Receive a message from a oneshot pipe.
1114+
fn recv_one<T: send>(+port: oneshot::server::oneshot<T>) -> T {
1115+
let oneshot::send(message) = recv(port);
1116+
message
1117+
}
1118+
1119+
/** Receive a message from a oneshot pipe, or fail if the connection
1120+
is closed.
1121+
1122+
*/
1123+
fn try_recv_one<T: send> (+port: oneshot::server::oneshot<T>) -> option<T> {
1124+
let message = try_recv(port);
1125+
1126+
if message == none { none }
1127+
else {
1128+
let oneshot::send(message) = option::unwrap(message);
1129+
some(message)
1130+
}
1131+
}
1132+
11061133
#[cfg(test)]
11071134
mod test {
11081135
#[test]
@@ -1119,4 +1146,13 @@ mod test {
11191146

11201147
c2.send(123);
11211148
}
1149+
1150+
#[test]
1151+
fn test_oneshot() {
1152+
let (c, p) = oneshot::init();
1153+
1154+
oneshot::client::send(c, ());
1155+
1156+
recv_one(p)
1157+
}
11221158
}

0 commit comments

Comments
 (0)