JSPM

toutsuite

0.6.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 576
  • Score
    100M100P100Q91868F
  • License MIT

Runs a block of code with synchronously executing promises

Package Exports

  • toutsuite

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (toutsuite) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

toutsuite

Run your Promise code as synchronously as possible

This library attempts to make code written using Promises to run synchronously, kind of.

But how is that possible!

This library only works with code that doesn't actually use any real sources of asynchrony - i.e. code whose promises only are combinations of then, resolve, and reject. Any code that uses a real source of asynchrony (i.e. setTimeout, fs.readFile, etc etc) will still run asynchronously.

However, certain libraries like PostCSS for the most part are not actually async, so this library will let you use it synchronously.

Examples

// Normally, Promise guarantees that it will be scheduled on the next tick
// (aka a "microtask")
let result = toutSuite(() => Promise.resolve(5).then((x) => x * 10));
console.log(result);
>>> 50