yieldish

yieldish ===

Usage no npm install needed!

<script type="module">
  import yieldish from 'https://cdn.skypack.dev/yieldish';
</script>

README

yieldish

NPM version Build status Downloads

Generate a sync and async variant of some function. This is useful when you want to ensure the same code is used for both sync and async without needing to duplicate the implementation code.adders.sync(3)

Usage

const { yieldish } = require('yieldish');

const adders = yieldish(isSync => function *(firstNumber) {
  const secondNumber = yield isSync ? 1 : Promise.resolve(1);
  return firstNumber + secondNumber;
});

adders.sync(3) === 4; // true
await adders.sync(3) === 4; // true