Skip to content

Commit

Permalink
test stub
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Nov 15, 2024
1 parent 3b4f1e2 commit 37cb902
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions py-gxhash/gxhash.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,5 @@ async def gxhash128_async(input_bytes: bytes, seed: int) -> int:
asyncio.run(main())
```
"""

async def test_async(): ...
15 changes: 15 additions & 0 deletions py-gxhash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ fn gxhash128_async<'p>(py: Python<'p>, input_bytes: Bound<'p, PyAny>, seed: i64)
})
}

#[pyfunction]
fn test_async(py: Python<'_>) -> PyResult<Bound<'_, PyAny>> {
pyo3_async_runtimes::tokio::future_into_py(py, async move {
let result = tokio::task::spawn_blocking(move || {
std::thread::sleep(std::time::Duration::from_secs(1));
42
})
.await
.unwrap();

Ok(result)
})
}

#[pymodule(name = "gxhash")]
fn pygxhash(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(gxhash32, m)?)?;
Expand All @@ -77,5 +91,6 @@ fn pygxhash(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(gxhash128, m)?)?;
m.add_function(wrap_pyfunction!(gxhash128_nogil, m)?)?;
m.add_function(wrap_pyfunction!(gxhash128_async, m)?)?;
m.add_function(wrap_pyfunction!(test_async, m)?)?;
Ok(())
}

0 comments on commit 37cb902

Please sign in to comment.