Skip to content

Commit 2ac2883

Browse files
committed
Add pipes::oneshot(), pipes::send_one(), pipes::try_send_one() wrappers.
1 parent 4ec1dd9 commit 2ac2883

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/libcore/pipes.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,16 +1144,22 @@ proto! oneshot {
11441144
}
11451145
}
11461146

1147-
/// Receive a message from a oneshot pipe.
1147+
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
1148+
fn oneshot<T: send>() -> (oneshot::client::oneshot<T>,
1149+
oneshot::server::oneshot<T>) {
1150+
oneshot::init()
1151+
}
1152+
1153+
/**
1154+
* Receive a message from a oneshot pipe, failing if the connection was
1155+
* closed.
1156+
*/
11481157
fn recv_one<T: send>(+port: oneshot::server::oneshot<T>) -> T {
11491158
let oneshot::send(message) = recv(port);
11501159
message
11511160
}
11521161

1153-
/** Receive a message from a oneshot pipe, or fail if the connection
1154-
is closed.
1155-
1156-
*/
1162+
/// Receive a message from a oneshot pipe unless the connection was closed.
11571163
fn try_recv_one<T: send> (+port: oneshot::server::oneshot<T>) -> option<T> {
11581164
let message = try_recv(port);
11591165

@@ -1164,6 +1170,20 @@ fn try_recv_one<T: send> (+port: oneshot::server::oneshot<T>) -> option<T> {
11641170
}
11651171
}
11661172

1173+
/// Send a message on a oneshot pipe, failing if the connection was closed.
1174+
fn send_one<T: send>(+chan: oneshot::client::oneshot<T>, +data: T) {
1175+
oneshot::client::send(chan, data);
1176+
}
1177+
1178+
/**
1179+
* Send a message on a oneshot pipe, or return false if the connection was
1180+
* closed.
1181+
*/
1182+
fn try_send_one<T: send>(+chan: oneshot::client::oneshot<T>, +data: T)
1183+
-> bool {
1184+
oneshot::client::try_send(chan, data).is_some()
1185+
}
1186+
11671187
#[cfg(test)]
11681188
mod test {
11691189
#[test]

0 commit comments

Comments
 (0)