Skip to content

Commit a1a7db1

Browse files
committed
add utils file
1 parent 93d163f commit a1a7db1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

jupyter_console/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import inspect
2+
import typing as t
3+
from jupyter_core.utils import run_sync as _run_sync
4+
5+
6+
T = t.TypeVar("T")
7+
8+
9+
def run_sync(coro: t.Callable[..., t.Union[T, t.Awaitable[T]]]) -> t.Callable[..., T]:
10+
"""Wraps coroutine in a function that blocks until it has executed.
11+
12+
Parameters
13+
----------
14+
coro : coroutine-function
15+
The coroutine-function to be executed.
16+
17+
Returns
18+
-------
19+
result :
20+
Whatever the coroutine-function returns.
21+
"""
22+
if not inspect.iscoroutinefunction(coro):
23+
return t.cast(t.Callable[..., T], coro)
24+
return _run_sync(coro)
25+

0 commit comments

Comments
 (0)