mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2025-01-08 13:51:58 -05:00
convert async/await to promise chain
This commit is contained in:
parent
1d5d6bfbb2
commit
cdd35b5296
1 changed files with 38 additions and 28 deletions
|
@ -108,24 +108,29 @@ tap.test('SoundPlayer', suite => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
suite.test('play while playing', async t => {
|
suite.test('play while playing', t => {
|
||||||
t.plan(15);
|
t.plan(15);
|
||||||
const log = [];
|
const log = [];
|
||||||
soundPlayer.play();
|
soundPlayer.play();
|
||||||
soundPlayer.finished().then(() => log.push('play 1 finished'));
|
soundPlayer.finished().then(() => log.push('play 1 finished'));
|
||||||
soundPlayer.connect(audioEngine);
|
soundPlayer.connect(audioEngine);
|
||||||
|
let oldPlayerNode;
|
||||||
|
|
||||||
await Promise.resolve();
|
return Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
|
||||||
audioContext.$processTo(0.005);
|
audioContext.$processTo(0.005);
|
||||||
t.equal(soundPlayer.outputNode.$state, 'PLAYING');
|
t.equal(soundPlayer.outputNode.$state, 'PLAYING');
|
||||||
|
|
||||||
const oldPlayerNode = soundPlayer.outputNode;
|
oldPlayerNode = soundPlayer.outputNode;
|
||||||
soundPlayer.play();
|
soundPlayer.play();
|
||||||
soundPlayer.finished().then(() => log.push('play 2 finished'));
|
soundPlayer.finished().then(() => log.push('play 2 finished'));
|
||||||
|
|
||||||
// wait for a micro-task loop to fire our previous events
|
// wait for a micro-task loop to fire our previous events
|
||||||
await Promise.resolve();
|
return Promise.resolve();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
|
||||||
t.equal(log[0], 'play 1 finished');
|
t.equal(log[0], 'play 1 finished');
|
||||||
t.notEqual(soundPlayer.outputNode, oldPlayerNode, 'created new player node');
|
t.notEqual(soundPlayer.outputNode, oldPlayerNode, 'created new player node');
|
||||||
|
|
||||||
|
@ -147,13 +152,18 @@ tap.test('SoundPlayer', suite => {
|
||||||
t.equal(log.length, 1);
|
t.equal(log.length, 1);
|
||||||
audioContext.$processTo(audioContext.currentTime + 0.2);
|
audioContext.$processTo(audioContext.currentTime + 0.2);
|
||||||
|
|
||||||
await Promise.resolve();
|
// wait for a micro-task loop to fire our previous events
|
||||||
|
return Promise.resolve();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
|
||||||
t.equal(log[1], 'play 2 finished');
|
t.equal(log[1], 'play 2 finished');
|
||||||
t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done');
|
t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done');
|
||||||
t.equal(log.length, 2);
|
t.equal(log.length, 2);
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
suite.end();
|
suite.end();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue