diff --git a/src/ffi/python/client.rs b/src/ffi/python/client.rs index b1e8f5b..c99ed34 100644 --- a/src/ffi/python/client.rs +++ b/src/ffi/python/client.rs @@ -13,16 +13,17 @@ impl Client { #[pyo3(name = "join_workspace")] fn pyjoin_workspace(&self, workspace: String) -> PyResult { - tracing::info!("attempting to join the workspace {workspace}"); + tracing::info!("attempting to join the workspace {}", workspace); - // crate::a_sync! { self => self.join_workspace(workspace).await } - let rc = self.clone(); - Ok(super::RustPromise(Some(tokio().spawn(async move { - Ok(rc - .join_workspace(workspace) - .await - .map(|f| Python::with_gil(|py| f.into_py(py)))?) - })))) + let this = self.clone(); + crate::a_sync!(this.join_workspace(workspace).await) + // let rc = self.clone(); + // Ok(super::RustPromise(Some(tokio().spawn(async move { + // Ok(rc + // .join_workspace(workspace) + // .await + // .map(|f| Python::with_gil(|py| f.into_py(py)))?) + // })))) } #[pyo3(name = "leave_workspace")] diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 6bc80bc..8046411 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -61,23 +61,14 @@ pub fn tokio() -> &'static tokio::runtime::Runtime { #[macro_export] macro_rules! a_sync { - ($($clone:ident)* => $x:expr) => { - { - $(let $clone = $clone.clone();)* - Ok($crate::ffi::python::RustPromise(Some($crate::ffi::python::tokio().spawn(async move { - Ok($x.map(|f| Python::with_gil(|py| f.into_py(py)))?) - })))) - } - }; + ($x:expr) => {{ + Ok($crate::ffi::python::RustPromise(Some( + $crate::ffi::python::tokio() + .spawn(async move { Ok($x.map(|f| Python::with_gil(|py| f.into_py(py)))?) }), + ))) + }}; } -// #[macro_export] -// macro_rules! spawn_future { -// ($fut:expr) => { -// $crate::ffi::python::tokio().spawn(async move { $fut.await }) -// }; -// } - #[derive(Debug, Clone)] struct LoggerProducer(mpsc::UnboundedSender); diff --git a/src/ffi/python/workspace.rs b/src/ffi/python/workspace.rs index 03f15df..eeaf4ac 100644 --- a/src/ffi/python/workspace.rs +++ b/src/ffi/python/workspace.rs @@ -3,23 +3,23 @@ use crate::cursor::Controller as CursorController; use crate::workspace::Workspace; use pyo3::prelude::*; -use crate::spawn_future; - +use super::RustPromise; +use crate::a_sync; // use super::Promise; #[pymethods] impl Workspace { // join a workspace #[pyo3(name = "create")] - async fn pycreate(&self, path: String) -> crate::Result<()> { - let rc = self.clone(); - spawn_future!(rc.create(path.as_str())).await.unwrap() + fn pycreate(&self, path: String) -> PyResult { + let this = self.clone(); + a_sync!(this.create(path.as_str()).await) } #[pyo3(name = "attach")] - async fn pyattach(&self, path: String) -> crate::Result { - let rc = self.clone(); - spawn_future!(rc.attach(path.as_str())).await.unwrap() + fn pyattach(&self, path: String) -> PyResult { + let this = self.clone(); + a_sync!(this.attach(path.as_str()).await) } #[pyo3(name = "detach")] @@ -31,37 +31,35 @@ impl Workspace { } } - // #[pyo3(name = "event")] - // fn pyevent(&self) -> Promise { - // crate::a_sync! { self => - // self.event().await - // } - // } + #[pyo3(name = "event")] + fn pyevent(&self) -> PyResult { + let this = self.clone(); + a_sync!(this.event().await) + } #[pyo3(name = "fetch_buffers")] - async fn pyfetch_buffers(&self) -> crate::Result<()> { - let rc = self.clone(); - spawn_future!(rc.fetch_buffers()).await.unwrap() + fn pyfetch_buffers(&self) -> PyResult { + let this = self.clone(); + a_sync!(this.fetch_buffers().await) } #[pyo3(name = "fetch_users")] - async fn pyfetch_users(&self) -> crate::Result<()> { - let rc = self.clone(); - spawn_future!(rc.fetch_users()).await.unwrap() + fn pyfetch_users(&self) -> PyResult { + let this = self.clone(); + a_sync!(this.fetch_users().await) } #[pyo3(name = "list_buffer_users")] - async fn pylist_buffer_users(&self, path: String) -> crate::Result> { - let rc = self.clone(); - spawn_future!(rc.list_buffer_users(path.as_str())) - .await - .unwrap() + fn pylist_buffer_users(&self, path: String) -> PyResult { + // crate::Result> { + let this = self.clone(); + a_sync!(this.list_buffer_users(path.as_str()).await) } #[pyo3(name = "delete")] - async fn pydelete(&self, path: String) -> crate::Result<()> { - let rc = self.clone(); - spawn_future!(rc.delete(path.as_str())).await.unwrap() + fn pydelete(&self, path: String) -> PyResult { + let this = self.clone(); + a_sync!(this.delete(path.as_str()).await) } #[pyo3(name = "id")]