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

source

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());
source

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§

source§

impl Debug for AudioWorkletHandle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.