@@ -608,6 +608,12 @@ def __init__(
608
608
) -> None :
609
609
super ().__init__ (iterator , buffersize , ordered )
610
610
self .transformation = wrap_error (transformation , StopIteration )
611
+ self .event_loop : asyncio .AbstractEventLoop
612
+ try :
613
+ self .event_loop = asyncio .get_event_loop ()
614
+ except RuntimeError :
615
+ self .event_loop = asyncio .new_event_loop ()
616
+ asyncio .set_event_loop (self .event_loop )
611
617
612
618
async def _safe_transformation (
613
619
self , elem : T
@@ -627,16 +633,16 @@ def _launch_task(
627
633
) -> "Future[Union[U, _RaisingIterator.ExceptionContainer]]" :
628
634
return cast (
629
635
"Future[Union[U, _RaisingIterator.ExceptionContainer]]" ,
630
- asyncio . get_event_loop () .create_task (self ._safe_transformation (elem )),
636
+ self . event_loop .create_task (self ._safe_transformation (elem )),
631
637
)
632
638
633
639
def _future_result_collection (
634
640
self ,
635
641
) -> FutureResultCollection [Union [U , _RaisingIterator .ExceptionContainer ]]:
636
642
if self .ordered :
637
- return FIFOAsyncFutureResultCollection ()
643
+ return FIFOAsyncFutureResultCollection (self . event_loop )
638
644
else :
639
- return FDFOAsyncFutureResultCollection ()
645
+ return FDFOAsyncFutureResultCollection (self . event_loop )
640
646
641
647
642
648
class AsyncConcurrentMapIterator (_RaisingIterator [U ]):
0 commit comments