blob: 6a8144b3ccfa8892efef71d921dad7ed4b0e1f88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/**
* @class PromiseProcessor
* @extends AudioWorkletProcessor
*
* This processor creates and resolves a promise in its `process` method. When
* the handler passed to `then()` is called, a counter that is global in the
* global scope is incremented. There are two copies of this
* AudioWorkletNode/Processor, so the counter should always be even in the
* process method of the AudioWorklet processing, since the Promise completion
* handler are resolved in between render quanta.
*
* After a few iterations of the test, one of the worklet posts back the string
* "ok" to the main thread, and the test is considered a success.
*/
var idx = 0;
class PromiseProcessor extends AudioWorkletProcessor {
constructor(options) {
super(options);
}
process(inputs, outputs) {
if (idx % 2 != 0) {
this.port.postMessage("ko");
// Don't bother continuing calling process in this case, the test has
// already failed.
return false;
}
Promise.resolve().then(() => {
idx++;
if (idx == 100) {
this.port.postMessage("ok");
}
});
// Ensure process is called again.
return true;
}
}
registerProcessor('promise-processor', PromiseProcessor);
|