This JavaScript segment is from a javascript controller of a lightning aura component. All I want to do is wait until a function is executed(code segment 1) and based on its