title: How to wait FileReader.onload loads file successfully?
body: <p>what I want to do is just simply read multiple file information through for loop. However, Javascript does not wait for the FileReader.onload even if I used Promise.</p>
  <p>How can we wait for the FileReader.onload ? Here is the code example.</p>
  <pre><code>    const promises = [];
      for (let i = 0; i &lt; files.length; i++) {
        promises.push(
          new Promise((resolve, reject) =&gt; {
            const fileReader = new FileReader();
            const filename = files[i].object.name;
  
            audioDict.filename[i] = filename;
            fileReader.readAsArrayBuffer(files[i].object);
            fileReader.onload = function (e: any) {
              audioCtx
                .decodeAudioData(e.target.result)
                .then(function (decodedData: AudioBuffer) {
                  // source.buffer = decodedData;
  
                  audioDict.audio[i] = {};
                  for (let c = 0; c &lt; decodedData.numberOfChannels; c++) {
                    audioDict.audio[i][c] = decodedData.getChannelData(c);
                  }
                  audioDict.sr[i] = decodedData.sampleRate;
                });
            };
            resolve(audioDict);
          })
        );
      }
  
      Promise.all(promises).then(() =&gt; {
        // Do something using audioDict here.
        console.log(&quot;done!&quot;);
      });
  </code></pre>