File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 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"
1010force-inprocess = []
1111memfd = [" syscall" ]
1212unstable = []
13+ async = [" futures" ]
1314
1415[dependencies ]
1516bincode = " 0.8"
@@ -24,6 +25,7 @@ fnv = "1.0.3"
2425mio = " 0.6.1"
2526
2627syscall = { version = " 0.2.1" , optional = true }
28+ futures = { version = " 0.1" , optional = true }
2729
2830[dev-dependencies ]
2931crossbeam = " 0.2"
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ use std::marker::PhantomData;
2020use std:: mem;
2121use std:: ops:: Deref ;
2222
23+ #[ cfg( feature = "async" ) ]
24+ use futures:: { Async , Poll , Stream } ;
25+ #[ cfg( feature = "async" ) ]
26+ use std:: io:: ErrorKind ;
27+
2328thread_local ! {
2429 static OS_IPC_CHANNELS_FOR_DESERIALIZATION : RefCell <Vec <OsOpaqueIpcChannel >> =
2530 RefCell :: new( Vec :: new( ) )
@@ -86,6 +91,27 @@ impl<T> IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
8691 }
8792}
8893
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+
89115impl < ' de , T > Deserialize < ' de > for IpcReceiver < T > where T : for < ' dde > Deserialize < ' dde > + Serialize {
90116 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error > where D : Deserializer < ' de > {
91117 let index: usize = try!( Deserialize :: deserialize ( deserializer) ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ extern crate fnv;
3131#[ macro_use]
3232extern crate syscall;
3333
34+ #[ cfg( feature = "async" ) ]
35+ extern crate futures;
36+
3437
3538pub mod ipc;
3639pub mod platform;
You can’t perform that action at this time.
0 commit comments