@@ -83,19 +83,16 @@ impl Server {
83
83
pub async fn delete_allocations_by_username ( & self , username : String ) -> Result < ( ) > {
84
84
let tx = {
85
85
let command_tx = self . command_tx . lock ( ) . await ;
86
- command_tx. clone ( )
86
+ command_tx. clone ( ) . ok_or ( Error :: ErrClosed ) ?
87
87
} ;
88
- if let Some ( tx) = tx {
89
- let ( closed_tx, closed_rx) = mpsc:: channel ( 1 ) ;
90
- tx. send ( Command :: DeleteAllocations ( username, Arc :: new ( closed_rx) ) )
91
- . map_err ( |_| Error :: ErrClosed ) ?;
92
88
93
- closed_tx. closed ( ) . await ;
89
+ let ( closed_tx, closed_rx) = mpsc:: channel ( 1 ) ;
90
+ tx. send ( Command :: DeleteAllocations ( username, Arc :: new ( closed_rx) ) )
91
+ . map_err ( |_| Error :: ErrClosed ) ?;
94
92
95
- Ok ( ( ) )
96
- } else {
97
- Err ( Error :: ErrClosed )
98
- }
93
+ closed_tx. closed ( ) . await ;
94
+
95
+ Ok ( ( ) )
99
96
}
100
97
101
98
/// Get information of [`Allocation`][`Allocation`]s by specified [`FiveTuple`]s.
@@ -121,23 +118,20 @@ impl Server {
121
118
122
119
let tx = {
123
120
let command_tx = self . command_tx . lock ( ) . await ;
124
- command_tx. clone ( )
121
+ command_tx. clone ( ) . ok_or ( Error :: ErrClosed ) ?
125
122
} ;
126
- if let Some ( tx) = tx {
127
- let ( infos_tx, mut infos_rx) = mpsc:: channel ( 1 ) ;
128
- tx. send ( Command :: GetAllocationsInfo ( five_tuples, infos_tx) )
129
- . map_err ( |_| Error :: ErrClosed ) ?;
130
123
131
- let mut info: HashMap < FiveTuple , AllocationInfo > = HashMap :: new ( ) ;
124
+ let ( infos_tx, mut infos_rx) = mpsc:: channel ( 1 ) ;
125
+ tx. send ( Command :: GetAllocationsInfo ( five_tuples, infos_tx) )
126
+ . map_err ( |_| Error :: ErrClosed ) ?;
132
127
133
- for _ in 0 ..tx. receiver_count ( ) {
134
- info. extend ( infos_rx. recv ( ) . await . ok_or ( Error :: ErrClosed ) ?) ;
135
- }
128
+ let mut info: HashMap < FiveTuple , AllocationInfo > = HashMap :: new ( ) ;
136
129
137
- Ok ( info)
138
- } else {
139
- Err ( Error :: ErrClosed )
130
+ for _ in 0 ..tx. receiver_count ( ) {
131
+ info. extend ( infos_rx. recv ( ) . await . ok_or ( Error :: ErrClosed ) ?) ;
140
132
}
133
+
134
+ Ok ( info)
141
135
}
142
136
143
137
async fn read_loop (
0 commit comments