@@ -76,6 +76,7 @@ export send_packet, recv_packet, send, recv, try_recv, peek;
76
76
export select, select2, selecti, select2i, selectable;
77
77
export spawn_service, spawn_service_recv;
78
78
export stream, port, chan, shared_chan, port_set, channel;
79
+ export oneshot, recv_one, try_recv_one;
79
80
80
81
#[ doc( hidden) ]
81
82
const SPIN_COUNT : uint = 0 ;
@@ -1103,6 +1104,32 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>>
1103
1104
}
1104
1105
}
1105
1106
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
+
1106
1133
#[ cfg( test) ]
1107
1134
mod test {
1108
1135
#[ test]
@@ -1119,4 +1146,13 @@ mod test {
1119
1146
1120
1147
c2. send ( 123 ) ;
1121
1148
}
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
+ }
1122
1158
}
0 commit comments