I have a conditional statement in which I need to perform one of two operations, and then continue after what operation was allowed. So my code is as follows:
if (shoud_do_thing_a) {
do_thing_a()
} else {
do_thing_b()
}
The problem is that, as do_thing_a
well as do_thing_b
return the Promises, and I can not move forward as long as the implementation is not met. The best way to solve this problem:
var more_code = function () {
}
if (shoud_do_thing_a) {
do_thing_a().then(more_code)
} else {
do_thing_b().then(more_code)
}
I do not like this structure. It is hard to follow because you need to jump to find where it is more_code
defined (imagine that I have this type of control flow in several places), and not just the ability to continue reading.
Is there a better way to handle this type of thing in javascript?
source
share