@@ -7,7 +7,7 @@ use crate::common::{get_timeout_time, now, CondvarBlocker};
77use crate :: coroutine:: suspender:: Suspender ;
88use crate :: scheduler:: { SchedulableCoroutine , Scheduler } ;
99use crate :: { error, impl_current_for, impl_display_by_debug, impl_for_named, trace} ;
10- use dashmap:: DashMap ;
10+ use dashmap:: { DashMap , DashSet } ;
1111use std:: cell:: Cell ;
1212use std:: ffi:: c_longlong;
1313use std:: io:: { Error , ErrorKind } ;
@@ -52,6 +52,7 @@ pub struct CoroutinePool<'p> {
5252 waits : DashMap < & ' p str , Arc < ( Mutex < bool > , Condvar ) > > ,
5353 //任务执行结果
5454 results : DashMap < String , Result < Option < usize > , & ' p str > > ,
55+ no_waits : DashSet < & ' p str > ,
5556}
5657
5758impl Drop for CoroutinePool < ' _ > {
@@ -136,6 +137,7 @@ impl<'p> CoroutinePool<'p> {
136137 blocker : Arc :: default ( ) ,
137138 results : DashMap :: new ( ) ,
138139 waits : DashMap :: default ( ) ,
140+ no_waits : DashSet :: default ( ) ,
139141 }
140142 }
141143
@@ -240,6 +242,14 @@ impl<'p> CoroutinePool<'p> {
240242 self . results . remove ( task_name) . map ( |( _, r) | r)
241243 }
242244
245+ /// clean the task result data.
246+ pub fn clean_task_result ( & self , task_name : & str ) {
247+ if self . try_take_task_result ( task_name) . is_some ( ) {
248+ return ;
249+ }
250+ _ = self . no_waits . insert ( Box :: leak ( Box :: from ( task_name) ) ) ;
251+ }
252+
243253 /// Use the given `task_name` to obtain task results, and if no results are found,
244254 /// block the current thread for `wait_time`.
245255 ///
@@ -375,6 +385,11 @@ impl<'p> CoroutinePool<'p> {
375385 fn try_run ( & self ) -> Option < ( ) > {
376386 self . task_queue . pop ( ) . map ( |task| {
377387 let ( task_name, result) = task. run ( ) ;
388+ let n = task_name. clone ( ) . leak ( ) ;
389+ if self . no_waits . contains ( n) {
390+ _ = self . no_waits . remove ( n) ;
391+ return ;
392+ }
378393 assert ! (
379394 self . results. insert( task_name. clone( ) , result) . is_none( ) ,
380395 "The previous result was not retrieved in a timely manner"
0 commit comments