toutsuite

Runs a block of code with synchronously executing promises


Keywords
promise
License
MIT
Install
npm install toutsuite@0.6.0

Documentation

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