Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add wasm fix for close in drop #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/storage/kv/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,28 @@ impl Store {
impl Drop for Store {
fn drop(&mut self) {
if let Some(inner) = self.inner.take() {
// Try to get existing runtime handle first
if let Ok(handle) = tokio::runtime::Handle::try_current() {
// We're in a runtime, spawn normally
handle.spawn(async move {
#[cfg(not(target_arch = "wasm32"))]
{
// Native environment - use tokio
if let Ok(handle) = tokio::runtime::Handle::try_current() {
handle.spawn(async move {
if let Err(err) = inner.close().await {
eprintln!("Error closing store: {}", err);
}
});
} else {
eprintln!("No runtime available for closing the store correctly");
}
}

#[cfg(target_arch = "wasm32")]
{
// WASM environment - use wasm_bindgen_futures
wasm_bindgen_futures::spawn_local(async move {
if let Err(err) = inner.close().await {
// TODO: use log/tracing instead of eprintln
eprintln!("Error closing store: {}", err);
}
});
} else {
eprintln!("No runtime available for closing the store correctly");
}
}
}
Expand Down
Loading