Skip to content

js promise demo

sleep

js
function sleep (time) {
  return new Promise((resolve) => {
    setTimeout(resolve, time)
  });
}

readFile

js
async function readFile(fileBlob: Blob) {
  return new Promise((resolve) => {
    const reader = new FileReader();
    reader.readAsText(fileBlob);
    reader.onloadend = () => resolve(reader.result);
  })
}

How to read files quickly in JavaScript

Released under the MIT License.