@@ -241,17 +241,16 @@ impl OfflineAudioContext {
241
241
}
242
242
} ;
243
243
244
- match renderer
244
+ let insert_pos = renderer
245
245
. suspend_promises
246
246
. binary_search_by_key ( & quantum, |& ( q, _) | q)
247
- {
248
- Ok ( _) => panic ! (
249
- "InvalidStateError: cannot suspend multiple times at the same render quantum"
250
- ) ,
251
- Err ( position) => renderer
252
- . suspend_promises
253
- . insert ( position, ( quantum, sender) ) ,
254
- }
247
+ . expect_err (
248
+ "InvalidStateError: cannot suspend multiple times at the same render quantum" ,
249
+ ) ;
250
+
251
+ renderer
252
+ . suspend_promises
253
+ . insert ( insert_pos, ( quantum, sender) ) ;
255
254
} // lock is dropped
256
255
257
256
receiver. await . unwrap ( )
@@ -306,17 +305,17 @@ impl OfflineAudioContext {
306
305
Some ( r) => r,
307
306
None => panic ! ( "InvalidStateError: cannot suspend when rendering has already started" ) ,
308
307
} ;
309
- match renderer
308
+
309
+ let insert_pos = renderer
310
310
. suspend_callbacks
311
311
. binary_search_by_key ( & quantum, |( q, _c) | * q)
312
- {
313
- Ok ( _) => panic ! (
314
- "InvalidStateError: cannot suspend multiple times at the same render quantum"
315
- ) ,
316
- Err ( position) => renderer
317
- . suspend_callbacks
318
- . insert ( position, ( quantum, Box :: new ( callback) ) ) ,
319
- }
312
+ . expect_err (
313
+ "InvalidStateError: cannot suspend multiple times at the same render quantum" ,
314
+ ) ;
315
+
316
+ renderer
317
+ . suspend_callbacks
318
+ . insert ( insert_pos, ( quantum, Box :: new ( callback) ) ) ;
320
319
}
321
320
322
321
/// Resumes the progression of the OfflineAudioContext's currentTime when it has been suspended
@@ -450,4 +449,12 @@ mod tests {
450
449
let _ = context. start_rendering_sync ( ) ;
451
450
context. suspend_sync ( 0.0 , |_| ( ) ) ;
452
451
}
452
+
453
+ #[ test]
454
+ #[ should_panic]
455
+ fn test_suspend_identical_frame_panics ( ) {
456
+ let mut context = OfflineAudioContext :: new ( 2 , 128 , 44_100. ) ;
457
+ context. suspend_sync ( 0.0 , |_| ( ) ) ;
458
+ context. suspend_sync ( 0.0 , |_| ( ) ) ;
459
+ }
453
460
}
0 commit comments