Struct web_thread::web::audio_worklet::AudioWorkletHandle
source · pub struct AudioWorkletHandle(/* private fields */);
Available on
Web
and crate feature audio-worklet
only.Expand description
Handle to the audio worklet. See BaseAudioContextExt::register_thread()
.
Implementations§
source§impl AudioWorkletHandle
impl AudioWorkletHandle
sourcepub const fn thread(&self) -> &Thread
pub const fn thread(&self) -> &Thread
Extracts a handle to the underlying thread.
§Example
use web_sys::{AudioContext, console};
use web_thread::web::audio_worklet::BaseAudioContextExt;
let context = AudioContext::new().unwrap();
let handle = context.clone().register_thread(
None,
|| {
// Do work.
},
).await.unwrap();
console::log_1(&format!("thread id: {:?}", handle.thread().id()).into());
sourcepub unsafe fn release(self) -> Result<(), ReleaseError>
pub unsafe fn release(self) -> Result<(), ReleaseError>
This releases memory allocated for the corresponding audio worklet thread.
§Safety
The corresponding thread must not currently or in the future access this Wasm module.
§Errors
If called from its corresponding audio worklet thread.
§Example
use wasm_bindgen_futures::JsFuture;
use web_sys::AudioContext;
use web_thread::web::audio_worklet::BaseAudioContextExt;
let context = AudioContext::new().unwrap();
let (sender, receiver) = async_channel::bounded(1);
let handle = context.clone().register_thread(
None,
move || {
// Do work.
sender.try_send(()).unwrap();
},
).await.unwrap();
// Wait until audio worklet is finished.
receiver.recv().await.unwrap();
JsFuture::from(context.close().unwrap()).await.unwrap();
// SAFETY: We are sure we are done with the audio worklet and didn't register any
// events or promises that could call into the Wasm module later.
unsafe { handle.release() }.unwrap();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AudioWorkletHandle
impl RefUnwindSafe for AudioWorkletHandle
impl Send for AudioWorkletHandle
impl Sync for AudioWorkletHandle
impl Unpin for AudioWorkletHandle
impl UnwindSafe for AudioWorkletHandle
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more