yieldish

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i yieldish

Weekly Downloads

4

Version

1.0.1

License

ISC

Unpacked Size

3.27 kB

Total Files

5

Last publish

Collaborators

  • kolodny