File tree 3 files changed +31
-0
lines changed
3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ repository = "https://github.com/servo/ipc-channel"
10
10
force-inprocess = []
11
11
memfd = [" syscall" ]
12
12
unstable = []
13
+ async = [" futures" ]
13
14
14
15
[dependencies ]
15
16
bincode = " 0.8"
@@ -24,6 +25,7 @@ fnv = "1.0.3"
24
25
mio = " 0.6.1"
25
26
26
27
syscall = { version = " 0.2.1" , optional = true }
28
+ futures = { version = " 0.1" , optional = true }
27
29
28
30
[dev-dependencies ]
29
31
crossbeam = " 0.2"
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ use std::marker::PhantomData;
20
20
use std:: mem;
21
21
use std:: ops:: Deref ;
22
22
23
+ #[ cfg( feature = "async" ) ]
24
+ use futures:: { Async , Poll , Stream } ;
25
+ #[ cfg( feature = "async" ) ]
26
+ use std:: io:: ErrorKind ;
27
+
23
28
thread_local ! {
24
29
static OS_IPC_CHANNELS_FOR_DESERIALIZATION : RefCell <Vec <OsOpaqueIpcChannel >> =
25
30
RefCell :: new( Vec :: new( ) )
@@ -86,6 +91,27 @@ impl<T> IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
86
91
}
87
92
}
88
93
94
+ #[ cfg( feature = "async" ) ]
95
+ impl < T > Stream for IpcReceiver < T > where T : for < ' de > Deserialize < ' de > + Serialize {
96
+ type Item = T ;
97
+ type Error = bincode:: Error ;
98
+
99
+ fn poll ( & mut self ) -> Poll < Option < Self :: Item > , Self :: Error > {
100
+ match self . try_recv ( ) {
101
+ Ok ( msg) => Ok ( Some ( msg) . into ( ) ) ,
102
+ Err ( err) => match * err {
103
+ bincode:: ErrorKind :: IoError ( ref e) if e. kind ( ) == ErrorKind :: ConnectionReset => {
104
+ Ok ( Async :: Ready ( None ) )
105
+ }
106
+ bincode:: ErrorKind :: IoError ( ref e) if e. kind ( ) == ErrorKind :: WouldBlock => {
107
+ Ok ( Async :: NotReady )
108
+ }
109
+ _ => Err ( err) ,
110
+ } ,
111
+ }
112
+ }
113
+ }
114
+
89
115
impl < ' de , T > Deserialize < ' de > for IpcReceiver < T > where T : for < ' dde > Deserialize < ' dde > + Serialize {
90
116
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error > where D : Deserializer < ' de > {
91
117
let index: usize = try!( Deserialize :: deserialize ( deserializer) ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ extern crate fnv;
31
31
#[ macro_use]
32
32
extern crate syscall;
33
33
34
+ #[ cfg( feature = "async" ) ]
35
+ extern crate futures;
36
+
34
37
35
38
pub mod ipc;
36
39
pub mod platform;
You can’t perform that action at this time.
0 commit comments