@@ -23,7 +23,7 @@ pub struct AsyncPool<F> {
2323 /// Name of the pool.
2424 name : & ' static str ,
2525 /// Transmission containing all tasks.
26- tx : kanal :: AsyncSender < F > ,
26+ tx : flume :: Sender < 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,34 +59,24 @@ where
5959 S : ThreadSpawn ,
6060 {
6161 let pool_name = builder. pool_name . unwrap_or ( DEFAULT_POOL_NAME ) ;
62- let ( tx, rx) = kanal :: bounded_async ( builder. num_threads * 2 ) ;
62+ let ( tx, rx) = flume :: bounded ( 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-
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- } ;
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+ ) ;
9080
9181 let thread = Thread {
9282 id : thread_id,
@@ -120,7 +110,7 @@ where
120110 /// the pool panicked.
121111 pub fn spawn ( & self , future : F ) {
122112 assert ! (
123- self . tx. as_sync ( ) . send( future) . is_ok( ) ,
113+ self . tx. send( future) . is_ok( ) ,
124114 "failed to schedule task: all worker threads have terminated (either none were spawned or all have panicked)"
125115 ) ;
126116 }
@@ -135,7 +125,7 @@ where
135125 /// the pool panicked.
136126 pub async fn spawn_async ( & self , future : F ) {
137127 assert ! (
138- self . tx. send ( future) . await . is_ok( ) ,
128+ self . tx. send_async ( future) . await . is_ok( ) ,
139129 "failed to schedule task: all worker threads have terminated (either none were spawned or all have panicked)"
140130 ) ;
141131 }
0 commit comments