We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 93d163f commit a1a7db1Copy full SHA for a1a7db1
jupyter_console/utils.py
@@ -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