I want to filter and route promise based on its result, so I use code like this that uses unresolved promise to omit executing of a branch:
const resultP = getSomething()
.then((result) => result === 'good' ? true : false )
const goodStuffP = resultP
// procceds if r is true, otherwise returns unresolved promise (so that branch is omitted)
.then((r) => r ? r : new Promise(() =>{}))
.then(...do good stuff...)
const badStuffP = resultP
// procceds if r is false, otherwise returns unresolved promise
.then((r) => !r ? r : new Promise(() =>{}))
.then(...do bad stuff...)
I wonder if something wrong with this approach, that thing that doesn't look ok to me is an unresolved promise.
So is using unresolved promise this way is a valid use in terms of possible tech issues (like leaks)? The question is not about good/bad programming style.