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

Make idb_sys::Transaction Clone #16

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 2 additions & 13 deletions idb-sys/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ use crate::{utils::dom_string_list_to_vec, Database, Error, ObjectStore};

/// Provides a static, asynchronous transaction on a database. All reading and writing of data is done within
/// transactions.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Transaction {
inner: IdbTransaction,
abort_callback: Option<Closure<dyn FnMut(Event)>>,
complete_callback: Option<Closure<dyn FnMut(Event)>>,
error_callback: Option<Closure<dyn FnMut(Event)>>,
}

impl Transaction {
Expand Down Expand Up @@ -71,7 +68,6 @@ impl Transaction {
let closure = Closure::once(callback);
self.inner
.set_onabort(Some(closure.as_ref().unchecked_ref()));
self.abort_callback = Some(closure);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this will drop the closure from memory once this function completes. This may lead to undefined behaviour.

}

/// Adds an event handler for `complete` event.
Expand All @@ -82,7 +78,6 @@ impl Transaction {
let closure = Closure::once(callback);
self.inner
.set_oncomplete(Some(closure.as_ref().unchecked_ref()));
self.complete_callback = Some(closure);
}

/// Adds an event handler for `error` event.
Expand All @@ -93,7 +88,6 @@ impl Transaction {
let closure = Closure::once(callback);
self.inner
.set_onerror(Some(closure.as_ref().unchecked_ref()));
self.error_callback = Some(closure);
}
}

Expand All @@ -111,12 +105,7 @@ impl TryFrom<EventTarget> for Transaction {

impl From<IdbTransaction> for Transaction {
fn from(inner: IdbTransaction) -> Self {
Self {
inner,
abort_callback: None,
complete_callback: None,
error_callback: None,
}
Self { inner }
}
}

Expand Down
Loading