Skip to content

Commit

Permalink
connect fn async runtime:
Browse files Browse the repository at this point in the history
  • Loading branch information
smartgoo committed Nov 28, 2024
1 parent f2f432e commit 454a5b2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions rpc/wrpc/bindings/python/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ impl RpcClient {
}

#[pyo3(signature = (block_async_connect=None, strategy=None, url=None, timeout_duration=None, retry_interval=None))]
pub fn connect(
pub fn connect<'py>(
&self,
py: Python,
py: Python<'py>,
block_async_connect: Option<bool>,
strategy: Option<String>,
url: Option<String>,
timeout_duration: Option<u64>,
retry_interval: Option<u64>,
) -> PyResult<Py<PyAny>> {
) -> PyResult<Bound<'py, PyAny>> {
let block_async_connect = block_async_connect.unwrap_or(true);
let strategy = match strategy {
Some(strategy) => ConnectStrategy::from_str(&strategy).map_err(|err| PyException::new_err(format!("{}", err)))?,
Expand All @@ -251,10 +251,15 @@ impl RpcClient {
self.start_notification_task(py)?;

let client = self.inner.client.clone();
py_async! {py, async move {
let _ = client.connect(Some(options)).await.map_err(|e| PyException::new_err(e.to_string()));
// py_async! {py, async move {
// let _ = client.connect(Some(options)).await.map_err(|e| PyException::new_err(e.to_string()))?;
// Ok(())
// }}

pyo3_async_runtimes::tokio::future_into_py(py, async move {
client.connect(Some(options)).await?;
Ok(())
}}
})
}

fn disconnect(&self, py: Python) -> PyResult<Py<PyAny>> {
Expand Down

0 comments on commit 454a5b2

Please sign in to comment.