yieldish
v1.0.1
Published
yieldish ===
Downloads
4
Readme
yieldish
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