Skip to content

Commit 3609057

Browse files
committed
fmt
1 parent 962c041 commit 3609057

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/lib.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::path::{Path, PathBuf};
1616
use std::sync::mpsc as std_mpsc;
1717
use std::thread;
1818
use thiserror::Error;
19-
use tokio::sync::{mpsc, oneshot};
2019
use tokio::runtime::Runtime;
20+
use tokio::sync::{mpsc, oneshot};
2121

2222
#[derive(Debug)]
2323
pub(crate) enum CmdType {
@@ -159,9 +159,17 @@ impl PyRunner {
159159
// This is the async `send_command` logic, but we can't call it
160160
// directly because of `&self` lifetime issues inside the closure.
161161
let (responder, receiver) = oneshot::channel();
162-
let cmd = PyCommand { cmd_type: cmd_type_clone, responder };
163-
sender.send(cmd).await.map_err(|_| PyRunnerError::SendCommandFailed)?;
164-
receiver.await.map_err(|_| PyRunnerError::ReceiveResultFailed.clone())?
162+
let cmd = PyCommand {
163+
cmd_type: cmd_type_clone,
164+
responder,
165+
};
166+
sender
167+
.send(cmd)
168+
.await
169+
.map_err(|_| PyRunnerError::SendCommandFailed)?;
170+
receiver
171+
.await
172+
.map_err(|_| PyRunnerError::ReceiveResultFailed.clone())?
165173
.map_err(PyRunnerError::PyError)
166174
});
167175
if tx.send(result.clone()).is_err() {
@@ -170,7 +178,9 @@ impl PyRunner {
170178
result
171179
});
172180

173-
SYNC_WORKER.send(task).map_err(|_| PyRunnerError::SendCommandFailed)?;
181+
SYNC_WORKER
182+
.send(task)
183+
.map_err(|_| PyRunnerError::SendCommandFailed)?;
174184
rx.recv().map_err(|_| PyRunnerError::ReceiveResultFailed)?
175185
}
176186
/// Asynchronously executes a block of Python code.
@@ -291,11 +301,7 @@ impl PyRunner {
291301
/// * `args`: A vector of `serde_json::Value` to pass as arguments to the function.
292302
///
293303
/// **Note:** This function is safe to call from any context (sync or async).
294-
pub fn call_function_sync(
295-
&self,
296-
name: &str,
297-
args: Vec<Value>,
298-
) -> Result<Value, PyRunnerError> {
304+
pub fn call_function_sync(&self, name: &str, args: Vec<Value>) -> Result<Value, PyRunnerError> {
299305
self.send_command_sync(CmdType::CallFunction {
300306
name: name.into(),
301307
args,
@@ -469,7 +475,6 @@ z = x + y"#;
469475
assert_eq!(z_val, Value::Number(30.into()));
470476
}
471477

472-
473478
#[tokio::test]
474479
async fn test_run_sync_from_async() {
475480
let executor = PyRunner::new();
@@ -486,7 +491,7 @@ z = x + y"#;
486491

487492
assert_eq!(z_val, Value::Number(30.into()));
488493
}
489-
494+
490495
#[tokio::test]
491496
async fn test_run_with_function() {
492497
// cargo test tests::test_run_with_function --release -- --nocapture
@@ -504,7 +509,10 @@ def add(a, b):
504509
.unwrap();
505510
assert_eq!(result, Value::Number(14.into()));
506511
let duration = start_time.elapsed();
507-
println!("test_run_with_function took: {} microseconds", duration.as_micros());
512+
println!(
513+
"test_run_with_function took: {} microseconds",
514+
duration.as_micros()
515+
);
508516
}
509517

510518
#[test]
@@ -523,7 +531,10 @@ def add(a, b):
523531
.unwrap();
524532
assert_eq!(result, Value::Number(14.into()));
525533
let duration = start_time.elapsed();
526-
println!("test_run_with_function_sync took: {} microseconds", duration.as_micros());
534+
println!(
535+
"test_run_with_function_sync took: {} microseconds",
536+
duration.as_micros()
537+
);
527538
}
528539

529540
#[cfg(feature = "pyo3")]
@@ -542,8 +553,10 @@ async def add_and_sleep(a, b, sleep_time):
542553
"#;
543554

544555
executor.run(code).await.unwrap();
545-
let result1 = executor.call_async_function("add_and_sleep", vec![5.into(), 10.into(), 1.into()]);
546-
let result2 = executor.call_async_function("add_and_sleep", vec![5.into(), 10.into(), 0.1.into()]);
556+
let result1 =
557+
executor.call_async_function("add_and_sleep", vec![5.into(), 10.into(), 1.into()]);
558+
let result2 =
559+
executor.call_async_function("add_and_sleep", vec![5.into(), 10.into(), 0.1.into()]);
547560
let (result1, result2) = tokio::join!(result1, result2);
548561
assert_eq!(result1.unwrap(), Value::Number(17.into()));
549562
assert_eq!(result2.unwrap(), Value::Number(16.into()));

0 commit comments

Comments
 (0)