We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0df9d9c commit eff773eCopy full SHA for eff773e
biothings/utils/mongo_async.py
@@ -79,6 +79,23 @@ def handle_autoreconnect_async(func):
79
MAX_RETRY = 30
80
SLEEP_TIME = 0.5 # seconds
81
82
+ if inspect.isasyncgenfunction(func):
83
+
84
+ @wraps(func)
85
+ async def inner_gen(*args, **kwargs):
86
+ retry = 0
87
+ while retry < MAX_RETRY:
88
+ try:
89
+ async for item in func(*args, **kwargs):
90
+ yield item
91
+ return
92
+ except AutoReconnect:
93
+ retry += 1
94
+ await asyncio.sleep(SLEEP_TIME)
95
+ raise MaxRetryAutoReconnectException()
96
97
+ return inner_gen
98
99
@wraps(func)
100
async def inner(*args, **kwargs):
101
retry = 0
0 commit comments