File tree 2 files changed +27
-22
lines changed
2 files changed +27
-22
lines changed Original file line number Diff line number Diff line change 1
1
workspace = { members = [" example" ] }
2
2
[package ]
3
3
name = " fast_pool"
4
- version = " 0.1.7 "
4
+ version = " 0.1.8 "
5
5
edition = " 2021"
6
6
description = " The Fast Pool based on channel"
7
7
readme = " README.md"
Original file line number Diff line number Diff line change @@ -82,30 +82,35 @@ impl<M: Manager> Pool<M> {
82
82
self . waits. fetch_sub( 1 , Ordering :: SeqCst ) ;
83
83
} ) ;
84
84
//pop connection from channel
85
+
85
86
let f = async {
86
- let idle = self . idle_send . len ( ) as u64 ;
87
- let connections = self . in_use . load ( Ordering :: SeqCst ) + idle;
88
- if connections < self . max_open . load ( Ordering :: SeqCst ) {
89
- let conn = self . manager . connect ( ) . await ?;
90
- self . idle_send
91
- . send ( conn)
87
+ loop {
88
+ let idle = self . idle_send . len ( ) as u64 ;
89
+ let connections = self . in_use . load ( Ordering :: SeqCst ) + idle;
90
+ if connections < self . max_open . load ( Ordering :: SeqCst ) {
91
+ //create connection
92
+ let conn = self . manager . connect ( ) . await ?;
93
+ self . idle_send
94
+ . send ( conn)
95
+ . map_err ( |e| M :: Error :: from ( & e. to_string ( ) ) ) ?;
96
+ }
97
+ let mut conn = self
98
+ . idle_recv
99
+ . recv_async ( )
100
+ . await
92
101
. map_err ( |e| M :: Error :: from ( & e. to_string ( ) ) ) ?;
93
- }
94
- let mut conn = self
95
- . idle_recv
96
- . recv_async ( )
97
- . await
98
- . map_err ( |e| M :: Error :: from ( & e. to_string ( ) ) ) ?;
99
- //check connection
100
- match self . manager . check ( & mut conn) . await {
101
- Ok ( _) => Ok ( conn) ,
102
- Err ( _e) => {
103
- //TODO some thing need return e?
104
- if false {
105
- return Err ( _e) ;
102
+ //check connection
103
+ match self . manager . check ( & mut conn) . await {
104
+ Ok ( _) => {
105
+ break Ok ( conn) ;
106
+ }
107
+ Err ( _e) => {
108
+ //TODO some thing need return e?
109
+ if false {
110
+ return Err ( _e) ;
111
+ }
112
+ continue ;
106
113
}
107
- conn = self . manager . connect ( ) . await ?;
108
- Ok ( conn)
109
114
}
110
115
}
111
116
} ;
You can’t perform that action at this time.
0 commit comments