Skip to content

Commit 230033f

Browse files
check if async func and await
1 parent 45cf138 commit 230033f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

singlestoredb/functions/ext/asgi.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,18 @@ async def do_func(
319319
row_ids = array_cls(row_ids)
320320

321321
# Call the function with `cols` as the function parameters
322+
is_async = inspect.iscoroutinefunction(func) or inspect.iscoroutinefunction(getattr(func, "__wrapped__", None))
322323
if cols and cols[0]:
323-
out = func(*[x if m else x[0] for x, m in zip(cols, masks)])
324+
if is_async:
325+
out = await func(*[x if m else x[0] for x, m in zip(cols, masks)])
326+
else:
327+
out = await asyncio.to_thread(func, *[x if m else x[0] for x, m in zip(cols, masks)])
324328
else:
325-
out = func()
326-
329+
if is_async:
330+
out = await func()
331+
else:
332+
out = await asyncio.to_thread(func())
333+
327334
# Single masked value
328335
if isinstance(out, Masked):
329336
return row_ids, [tuple(out)]

0 commit comments

Comments
 (0)