Skip to content

Commit 68da6a6

Browse files
committed
feat: add conversion from abort signal
1 parent db966f9 commit 68da6a6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/bitwarden-threading/src/cancellation_token.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,24 @@ pub mod wasm {
4040
}
4141

4242
impl AbortControllerExt for AbortController {
43+
fn to_cancellation_token(&self) -> CancellationToken {
44+
self.signal().to_cancellation_token()
45+
}
46+
}
47+
48+
pub trait AbortSignalExt {
49+
fn to_cancellation_token(&self) -> CancellationToken;
50+
}
51+
52+
impl AbortSignalExt for AbortSignal {
4353
fn to_cancellation_token(&self) -> CancellationToken {
4454
let token = CancellationToken::new();
4555

4656
let token_clone = token.clone();
4757
let closure = Closure::new(move || {
4858
token_clone.cancel();
4959
});
50-
self.signal().add_event_listener("abort", &closure);
60+
self.add_event_listener("abort", &closure);
5161
closure.forget(); // Transfer ownership to the JS runtime
5262

5363
token

0 commit comments

Comments
 (0)