File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,20 @@ func makeAsyncCreateItemFunc[PT ItemConstraint[T], T any]( //nolint:funlen
276276 case <- p .done :
277277 return nil , xerrors .WithStackTrace (errClosedPool )
278278 case <- ctx .Done ():
279+ // Try non-blocking read from ch to check if goroutine has already completed
280+ select {
281+ case result , has := <- ch :
282+ if has {
283+ if result .err != nil {
284+ // Goroutine completed with an error, join it with context error
285+ return nil , xerrors .WithStackTrace (xerrors .Join (result .err , ctx .Err ()))
286+ }
287+ // Goroutine completed successfully, return the item
288+ return result .item , nil
289+ }
290+ default :
291+ }
292+
279293 return nil , xerrors .WithStackTrace (ctx .Err ())
280294 case result , has := <- ch :
281295 if ! has {
You can’t perform that action at this time.
0 commit comments