Protractor/WebDriverJS has this mechanism called Control Flow - it is an internal queue of promises, it keeps the code execution organized.