@@ -22,7 +22,9 @@ use common_base::base::select3;
22
22
use common_base:: base:: tokio;
23
23
use common_base:: base:: tokio:: sync:: Notify ;
24
24
use common_base:: base:: tokio:: task:: JoinHandle ;
25
+ use common_base:: base:: Runtime ;
25
26
use common_base:: base:: Select3Output ;
27
+ use common_base:: base:: TrySpawn ;
26
28
use common_exception:: ErrorCode ;
27
29
use common_exception:: Result ;
28
30
@@ -36,17 +38,25 @@ pub struct StatisticsReceiver {
36
38
shutdown_flag : Arc < AtomicBool > ,
37
39
shutdown_notify : Arc < Notify > ,
38
40
exchange_handler : Vec < JoinHandle < Result < ( ) > > > ,
41
+ runtime : Arc < Runtime > ,
39
42
}
40
43
41
44
impl StatisticsReceiver {
42
- pub fn create ( ctx : Arc < QueryContext > , exchanges : Vec < FlightExchange > ) -> StatisticsReceiver {
43
- StatisticsReceiver {
45
+ pub fn create (
46
+ ctx : Arc < QueryContext > ,
47
+ exchanges : Vec < FlightExchange > ,
48
+ ) -> Result < StatisticsReceiver > {
49
+ Ok ( StatisticsReceiver {
44
50
ctx,
45
51
exchanges,
46
52
shutdown_flag : Arc :: new ( AtomicBool :: new ( false ) ) ,
47
53
shutdown_notify : Arc :: new ( Notify :: new ( ) ) ,
48
54
exchange_handler : vec ! [ ] ,
49
- }
55
+ runtime : Arc :: new ( Runtime :: with_worker_threads (
56
+ 2 ,
57
+ Some ( String :: from ( "StatisticsReceiver" ) ) ,
58
+ ) ?) ,
59
+ } )
50
60
}
51
61
52
62
pub fn start ( & mut self ) {
@@ -55,7 +65,7 @@ impl StatisticsReceiver {
55
65
let shutdown_flag = self . shutdown_flag . clone ( ) ;
56
66
let shutdown_notify = self . shutdown_notify . clone ( ) ;
57
67
58
- self . exchange_handler . push ( tokio :: spawn ( async move {
68
+ self . exchange_handler . push ( self . runtime . spawn ( async move {
59
69
let mut recv = Box :: pin ( flight_exchange. recv ( ) ) ;
60
70
let mut notified = Box :: pin ( shutdown_notify. notified ( ) ) ;
61
71
0 commit comments