5
5
from dataclasses import dataclass
6
6
from pathlib import Path
7
7
from time import time
8
- from typing import TYPE_CHECKING , Any , AsyncIterator , Generator , Iterator , Optional , TypeVar
8
+ from typing import TYPE_CHECKING , Any , AsyncIterator , Optional
9
9
10
10
from dateutil import parser
11
11
from pydantic import Field , Secret
@@ -101,27 +101,6 @@ class OnedriveIndexerConfig(IndexerConfig):
101
101
recursive : bool = False
102
102
103
103
104
- T = TypeVar ("T" )
105
-
106
-
107
- def async_iterable_to_sync_iterable (iterator : AsyncIterator [T ]) -> Iterator [T ]:
108
- # This version works on Python 3.9 by manually handling the async iteration.
109
- loop = asyncio .new_event_loop ()
110
- asyncio .set_event_loop (loop )
111
- try :
112
- while True :
113
- try :
114
- # Instead of anext(iterator), we directly call __anext__().
115
- # __anext__ returns a coroutine that we must run until complete.
116
- future = iterator .__anext__ ()
117
- result = loop .run_until_complete (future )
118
- yield result
119
- except StopAsyncIteration :
120
- break
121
- finally :
122
- loop .close ()
123
-
124
-
125
104
@dataclass
126
105
class OnedriveIndexer (Indexer ):
127
106
connection_config : OnedriveConnectionConfig
@@ -215,7 +194,10 @@ async def drive_item_to_file_data(self, drive_item: "DriveItem") -> FileData:
215
194
# Offload the file data creation if it's not guaranteed async
216
195
return await asyncio .to_thread (self .drive_item_to_file_data_sync , drive_item )
217
196
218
- async def _run_async (self , ** kwargs : Any ) -> AsyncIterator [FileData ]:
197
+ def is_async (self ) -> bool :
198
+ return True
199
+
200
+ async def run_async (self , ** kwargs : Any ) -> AsyncIterator [FileData ]:
219
201
token_resp = await asyncio .to_thread (self .connection_config .get_token )
220
202
if "error" in token_resp :
221
203
raise SourceConnectionError (
@@ -230,12 +212,6 @@ async def _run_async(self, **kwargs: Any) -> AsyncIterator[FileData]:
230
212
file_data = await self .drive_item_to_file_data (drive_item = drive_item )
231
213
yield file_data
232
214
233
- def run (self , ** kwargs : Any ) -> Generator [FileData , None , None ]:
234
- # Convert the async generator to a sync generator without loading all data into memory
235
- async_gen = self ._run_async (** kwargs )
236
- for item in async_iterable_to_sync_iterable (async_gen ):
237
- yield item
238
-
239
215
240
216
class OnedriveDownloaderConfig (DownloaderConfig ):
241
217
pass
0 commit comments