diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index d9090b38..3b2163c5 100755 --- a/singlestoredb/functions/ext/asgi.py +++ b/singlestoredb/functions/ext/asgi.py @@ -326,15 +326,16 @@ async def do_func( rows: Sequence[Sequence[Any]], ) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]: '''Call function on given rows of data.''' - out = [] + tasks = [] async with timer('call_function'): for row in rows: cancel_on_event(cancel_event) if is_async: - out.append(await func(*row)) + tasks.append(func(*row)) else: - out.append(func(*row)) - return row_ids, list(zip(out)) + tasks.append(asyncio.to_thread(func, *row)) + + return row_ids, list(zip(await asyncio.gather(*tasks))) return do_func