FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi/python/src/async_callback.rs at main · ZGeomantic/openapi · GitHub
ZGeomantic
/
openapi
Public
forked from
longbridge/openapi
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openapi
/
python
/
src
/
async_callback.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (29 loc) · 907 Bytes
Breadcrumbs
openapi
/
python
/
src
/
async_callback.rs
Copy path
File metadata and controls
31 lines (29 loc) · 907 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Invoke a Python callback and, if it returns a coroutine and an event loop
//! is provided, schedule the coroutine on that loop (for use from non-asyncio
//! threads).
use
pyo3
::
prelude
::
*
;
/// If `result` is a coroutine and `event_loop` is `Some`, schedules it on the
/// loop via `asyncio.run_coroutine_threadsafe(coro, loop)`.
pub
(
crate
)
fn
schedule_coro_if_needed
(
result
:
&
Bound
<
PyAny
>
,
event_loop
:
Option
<
&
Bound
<
PyAny
>
>
,
py
:
Python
<
'
_
>
,
)
->
PyResult
<
(
)
>
{
let
Some
(
loop_ref
)
= event_loop
else
{
return
Ok
(
(
)
)
;
}
;
if
result
.
is_none
(
)
{
return
Ok
(
(
)
)
;
}
let
asyncio = py
.
import
(
"asyncio"
)
?
;
let
is_coro = asyncio
.
getattr
(
"iscoroutine"
)
?
.
call1
(
(
result
,
)
)
?
.
extract
::
<
bool
>
(
)
?
;
if
is_coro
{
asyncio
.
getattr
(
"run_coroutine_threadsafe"
)
?
.
call1
(
(
result
,
loop_ref
)
)
?
;
}
Ok
(
(
)
)
}
Back
|
FazBrowse Home
|
New Git URL