Skip to content

cometkim/concurrently.macro

Repository files navigation

concurrently.macro

npm Babel Macro

Transforms your async function to be run concurrently much as possible.

Features

  • Bundles multiple await expressions into a single Promise.all expression
  • Simple dependency analysis
  • Graph dependency analysis
  • Limit maximum concurrency
  • Insert side-effects

Install

yarn add concurrently.macro

Make sure you have babel-plugin-macros in your Babel config.

Usage

import concurrently from 'concurrently.macro';

concurrently(async () => {
  const a = await defer(1);
  const b = await defer(2);
});

This becomes:

async () => {
  let { 0: a, 1: b } = await Promise.all([defer(1), defer(2)]); 
};

Macros can handle more complex example like dependencies and destructuring!

LICENSE

MIT