Skip to content

Commit 63767d2

Browse files
committed
Throw InvalidStateError when calling suspend while rendering has started
This is slightly different from the spec, where it says we should throw if the suspend time is less than or equal to the current time. However, this is more or less the same because rendering happens so fast the user does not even know about the precise 'current time' anyway.
1 parent 2eead6f commit 63767d2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/context/offline.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ impl OfflineAudioContext {
222222
// We are mixing async with a std Mutex, so be sure not to `await` while the lock is held
223223
{
224224
let mut lock = self.renderer.lock().unwrap();
225-
let renderer = lock.as_mut().unwrap();
225+
let renderer = match lock.as_mut() {
226+
Some(r) => r,
227+
None => {
228+
panic!("InvalidStateError: cannot suspend when rendering has already started")
229+
}
230+
};
226231

227232
match renderer.suspend_promises.entry(quantum) {
228233
Entry::Occupied(_) => panic!(
@@ -283,7 +288,10 @@ impl OfflineAudioContext {
283288
.ceil() as usize;
284289

285290
let mut lock = self.renderer.lock().unwrap();
286-
let renderer = lock.as_mut().unwrap();
291+
let renderer = match lock.as_mut() {
292+
Some(r) => r,
293+
None => panic!("InvalidStateError: cannot suspend when rendering has already started"),
294+
};
287295
match renderer.suspend_callbacks.entry(quantum) {
288296
Entry::Occupied(_) => panic!(
289297
"InvalidStateError: cannot suspend multiple times at the same render quantum"

0 commit comments

Comments
 (0)