Promise Flow Control Dilemma

Note: With async and await syntax, this is no longer a problem: var input = getInput() if (sanityCheck(input)) { if (isEdit) { var obj = await db.findById(id).exec() await update(obj, input) } else { obj = await newObject(input) } await modifyAndSaveObject(obj) } else { throw(new Error('Invalid input')) } Promise in flow control IF…ELSE… In sequential programming, we can easily use if...else to diverge the code into different control flow paths, then after that, merge the control together. Read more →