Skip to content

Commit

Permalink
fix(core): safe_block_on usage on async contexts, closes #3505 (#3513)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 24, 2022
1 parent 944b124 commit 0163489
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-safe-block-on.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes `Command::output` and `Command::status` deadlock when running on async commands.
7 changes: 4 additions & 3 deletions core/tauri/src/async_runtime.rs
Expand Up @@ -285,10 +285,11 @@ where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
if tokio::runtime::Handle::try_current().is_ok() {
if let Ok(handle) = tokio::runtime::Handle::try_current() {
let (tx, rx) = std::sync::mpsc::sync_channel(1);
spawn(async move {
tx.send(task.await).unwrap();
let handle_ = handle.clone();
handle.spawn_blocking(move || {
tx.send(handle_.block_on(task)).unwrap();
});
rx.recv().unwrap()
} else {
Expand Down

0 comments on commit 0163489

Please sign in to comment.