@@ -70,28 +70,29 @@ impl App {
70
70
O : ' static + Sink < SinkItem = OutgoingMessage > ,
71
71
I : ' static + Stream < Item = IncomingMessage , Error = io:: Error >
72
72
{
73
- {
74
- let mut inner = inner. borrow_mut ( ) ;
75
- let ( tx, rx) = mpsc:: unbounded ( ) ;
76
- if inner. app_channel . is_some ( ) {
77
- eprintln ! ( "Redundant app client" ) ;
78
- return ;
79
- }
80
-
81
- inner. app_channel = Some ( tx) ;
82
- inner. reactor . spawn (
83
- outgoing. send_all ( rx. map_err ( |_| unreachable ! ( ) ) ) . then ( |_| Ok ( ( ) ) )
84
- ) ;
73
+ let mut inner_borrow = inner. borrow_mut ( ) ;
74
+ let ( tx, rx) = mpsc:: unbounded ( ) ;
75
+ if inner_borrow. app_channel . is_some ( ) {
76
+ eprintln ! ( "Redundant app client" ) ;
77
+ return ;
85
78
}
86
79
87
- Self :: handle_app_messages ( inner, incoming) ;
80
+ inner_borrow. app_channel = Some ( tx) ;
81
+
82
+ let receive_incoming = Self :: handle_app_messages ( inner. clone ( ) , incoming) ;
83
+ let send_outgoing = outgoing. send_all ( rx. map_err ( |_| unreachable ! ( ) ) ) . then ( |_| Ok ( ( ) ) ) ;
84
+ inner_borrow. reactor . spawn (
85
+ receive_incoming
86
+ . select ( send_outgoing)
87
+ . then ( |_: Result < ( ( ) , _ ) , ( ( ) , _ ) > | Ok ( ( ) ) )
88
+ ) ;
88
89
}
89
90
90
91
fn start_cli < I > ( inner : Rc < RefCell < Inner > > , incoming : I )
91
92
where
92
93
I : ' static + Stream < Item = IncomingMessage , Error = io:: Error >
93
94
{
94
- Self :: handle_app_messages ( inner, incoming) ;
95
+ inner . borrow_mut ( ) . reactor . spawn ( Self :: handle_app_messages ( inner. clone ( ) , incoming) ) ;
95
96
}
96
97
97
98
fn start_window < O , I > ( inner : Rc < RefCell < Inner > > , outgoing : O , incoming : I , window_id : WindowId )
@@ -119,18 +120,14 @@ impl App {
119
120
) ;
120
121
}
121
122
122
- fn handle_app_messages < I > ( inner : Rc < RefCell < Inner > > , incoming : I )
123
+ fn handle_app_messages < I > ( inner : Rc < RefCell < Inner > > , incoming : I ) -> Box < Future < Item = ( ) , Error = ( ) > >
123
124
where
124
125
I : ' static + Stream < Item = IncomingMessage , Error = io:: Error >
125
126
{
126
- let inner_clone = inner. clone ( ) ;
127
- let inner = inner. borrow_mut ( ) ;
128
- inner. reactor . spawn (
129
- incoming. for_each ( move |message| {
130
- inner_clone. borrow_mut ( ) . handle_app_message ( message) ;
131
- Ok ( ( ) )
132
- } ) . then ( |_| Ok ( ( ) ) )
133
- ) ;
127
+ Box :: new ( incoming. for_each ( move |message| {
128
+ inner. borrow_mut ( ) . handle_app_message ( message) ;
129
+ Ok ( ( ) )
130
+ } ) . then ( |_| Ok ( ( ) ) ) )
134
131
}
135
132
}
136
133
0 commit comments