Search code examples
javascriptasync-awaitreasonreasonml

Does ReasonML support async/await?


I have been going through the JS -> Reason cheatsheet on the Reason ML website. They are very helpful, but none cover the async/await syntax available in modern ES.

What is the Reason ML equivalent of this?

import fs from 'mz/fs';

// A cat-like utility
const main = async () => {
  if (process.argv.length != 3) {
    throw new Error('Expected a file-path');
  }
  const path = process.argv[2];
  const content = await fs.readFile(path);
  console.log(content.toString());
};

main().catch(error => console.error(error));

Solution

  • ReasonML documentation says:

    Note: we might offer a dedicated syntax for JS promises (async/await) in the future.

    Which means it doesn't currently support async/await.