For sync code I do:
return opts || (opts = getOpts())
To make sure things are easily cached/initialized.
What is the easiest to do this in async/promise pattern?
Currently I have a repeating boilerplate
if (result) {
return Promise.resolve(result);
} else {
return getResult().then(_result => {
result = _result;
return result;
}
}
Which is annoying when done multiple times.
Libraries I find are either unmaintained or offer unfriendly syntax.
Any suggestions or ideas?