@@ -23,7 +23,7 @@ pub struct AsyncPool<F> {
2323 /// Name of the pool.
2424 name : & ' static str ,
2525 /// Transmission containing all tasks.
26- tx : flume :: Sender < F > ,
26+ tx : kanal :: AsyncSender < F > ,
2727 /// The maximum number of tasks that are expected to run concurrently at any point in time.
2828 max_tasks : u64 ,
2929 /// Vector containing all the metrics collected individually in each thread.
@@ -59,24 +59,34 @@ where
5959 S : ThreadSpawn ,
6060 {
6161 let pool_name = builder. pool_name . unwrap_or ( DEFAULT_POOL_NAME ) ;
62- let ( tx, rx) = flume :: bounded ( builder. num_threads * 2 ) ;
62+ let ( tx, rx) = kanal :: bounded_async ( builder. num_threads * 2 ) ;
6363 let mut threads_metrics = Vec :: with_capacity ( builder. num_threads ) ;
6464
6565 for thread_id in 0 ..builder. num_threads {
6666 let rx = rx. clone ( ) ;
6767
6868 let thread_name: Option < String > = builder. thread_name . as_mut ( ) . map ( |f| f ( thread_id) ) ;
6969 let metrics = Arc :: new ( ThreadMetrics :: default ( ) ) ;
70- let task = MonitoredFuture :: wrap_with_metrics (
71- Multiplexed :: new (
72- pool_name,
73- builder. max_concurrency ,
74- rx. into_stream ( ) ,
75- builder. task_panic_handler . clone ( ) ,
76- metrics. clone ( ) ,
77- ) ,
78- metrics. raw_metrics . clone ( ) ,
79- ) ;
70+
71+ let task = {
72+ let metrics = Arc :: clone ( & metrics) ;
73+ let task_panic_handler = builder. task_panic_handler . clone ( ) ;
74+ async move {
75+ let stream = rx. stream ( ) ;
76+
77+ MonitoredFuture :: wrap_with_metrics (
78+ Multiplexed :: new (
79+ pool_name,
80+ builder. max_concurrency ,
81+ stream,
82+ task_panic_handler,
83+ metrics. clone ( ) ,
84+ ) ,
85+ metrics. raw_metrics . clone ( ) ,
86+ )
87+ . await
88+ }
89+ } ;
8090
8191 let thread = Thread {
8292 id : thread_id,
@@ -110,7 +120,7 @@ where
110120 /// the pool panicked.
111121 pub fn spawn ( & self , future : F ) {
112122 assert ! (
113- self . tx. send( future) . is_ok( ) ,
123+ self . tx. as_sync ( ) . send( future) . is_ok( ) ,
114124 "failed to schedule task: all worker threads have terminated (either none were spawned or all have panicked)"
115125 ) ;
116126 }
@@ -125,7 +135,7 @@ where
125135 /// the pool panicked.
126136 pub async fn spawn_async ( & self , future : F ) {
127137 assert ! (
128- self . tx. send_async ( future) . await . is_ok( ) ,
138+ self . tx. send ( future) . await . is_ok( ) ,
129139 "failed to schedule task: all worker threads have terminated (either none were spawned or all have panicked)"
130140 ) ;
131141 }
0 commit comments