1.0.1 • Published 4 years ago

yieldish v1.0.1

Weekly downloads
5
License
ISC
Repository
github
Last release
4 years ago

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