1- use crate :: {
2- errors:: { ErrorKind , RSocketError } ,
3- frame,
4- payload:: { Payload , SetupPayload } ,
5- result:: RSocketResult ,
6- } ;
1+ use crate :: errors:: { ErrorKind , RSocketError } ;
2+ use crate :: frame;
3+ use crate :: payload:: { Payload , SetupPayload } ;
4+ use crate :: result:: RSocketResult ;
75use futures:: future;
6+ use futures:: { Sink , SinkExt , Stream , StreamExt } ;
87use std:: future:: Future ;
98use std:: pin:: Pin ;
109use std:: sync:: Arc ;
1110
12- pub type Single < T > = Pin < Box < dyn Send + Sync + Future < Output = RSocketResult < T > > > > ;
11+ // TODO: switch to reactor-rust.
12+ pub type Mono < T > = Pin < Box < dyn Send + Sync + Future < Output = RSocketResult < T > > > > ;
13+ pub type Flux < T > = Pin < Box < dyn Send + Sync + Stream < Item = RSocketResult < T > > > > ;
1314
1415pub trait RSocket : Sync + Send {
15- fn metadata_push ( & self , req : Payload ) -> Single < ( ) > ;
16- fn fire_and_forget ( & self , req : Payload ) -> Single < ( ) > ;
17- fn request_response ( & self , req : Payload ) -> Single < Payload > ;
16+ fn metadata_push ( & self , req : Payload ) -> Mono < ( ) > ;
17+ fn fire_and_forget ( & self , req : Payload ) -> Mono < ( ) > ;
18+ fn request_response ( & self , req : Payload ) -> Mono < Payload > ;
19+ fn request_stream ( & self , req : Payload ) -> Flux < Payload > ;
20+ // fn request_channel(&self, reqs: Flux<Payload>) -> Flux<Payload>;
1821}
1922
2023pub struct EchoRSocket ;
2124
2225impl RSocket for EchoRSocket {
23- fn metadata_push ( & self , req : Payload ) -> Single < ( ) > {
26+ fn metadata_push ( & self , req : Payload ) -> Mono < ( ) > {
27+ info ! ( "echo metadata_push: {:?}" , req) ;
2428 Box :: pin ( future:: ok :: < ( ) , RSocketError > ( ( ) ) )
2529 }
26- fn fire_and_forget ( & self , req : Payload ) -> Single < ( ) > {
30+ fn fire_and_forget ( & self , req : Payload ) -> Mono < ( ) > {
2731 info ! ( "echo fire_and_forget: {:?}" , req) ;
2832 Box :: pin ( future:: ok :: < ( ) , RSocketError > ( ( ) ) )
2933 }
30-
31- fn request_response ( & self , req : Payload ) -> Single < Payload > {
34+ fn request_response ( & self , req : Payload ) -> Mono < Payload > {
3235 info ! ( "echo request_response: {:?}" , req) ;
3336 Box :: pin ( future:: ok :: < Payload , RSocketError > ( req) )
3437 }
38+ fn request_stream ( & self , req : Payload ) -> Flux < Payload > {
39+ info ! ( "echo request_stream: {:?}" , req) ;
40+ Box :: pin ( futures:: stream:: iter ( vec ! [
41+ Ok ( req. clone( ) ) ,
42+ Ok ( req. clone( ) ) ,
43+ Ok ( req) ,
44+ ] ) )
45+ }
3546}
3647
3748pub struct EmptyRSocket ;
@@ -43,17 +54,21 @@ impl EmptyRSocket {
4354}
4455
4556impl RSocket for EmptyRSocket {
46- fn metadata_push ( & self , _req : Payload ) -> Single < ( ) > {
57+ fn metadata_push ( & self , _req : Payload ) -> Mono < ( ) > {
4758 Box :: pin ( future:: err ( self . must_failed ( ) ) )
4859 }
4960
50- fn fire_and_forget ( & self , _req : Payload ) -> Single < ( ) > {
61+ fn fire_and_forget ( & self , _req : Payload ) -> Mono < ( ) > {
5162 Box :: pin ( future:: err ( self . must_failed ( ) ) )
5263 }
5364
54- fn request_response ( & self , _req : Payload ) -> Single < Payload > {
65+ fn request_response ( & self , _req : Payload ) -> Mono < Payload > {
5566 Box :: pin ( future:: err ( self . must_failed ( ) ) )
5667 }
68+
69+ fn request_stream ( & self , req : Payload ) -> Flux < Payload > {
70+ Box :: pin ( futures:: stream:: empty ( ) )
71+ }
5772}
5873
5974pub type AcceptorGenerator = Arc < fn ( SetupPayload , Box < dyn RSocket > ) -> Box < dyn RSocket > > ;
0 commit comments