Simplify cooperation of sync and async code in JavaScript