loaded promise allows for downloads to be added while 'loaded' is awaiting

This commit is contained in:
Yotam Mann 2020-03-17 22:45:59 -04:00
parent faa68aa2d1
commit 85f70621ef

View file

@ -407,8 +407,10 @@ export class ToneAudioBuffer extends Tone {
* Returns a Promise which resolves when all of the buffers have loaded
*/
static async loaded(): Promise<void> {
await Promise.all(ToneAudioBuffer.downloads);
// this makes sure that the function is always async
return Promise.resolve();
await Promise.resolve();
while (ToneAudioBuffer.downloads.length) {
await ToneAudioBuffer.downloads[0];
}
}
}