示例#1
0
// generateWithShortCircuiting generates an expression with automatic short circuiting based on the value found
// in the resultName variable and compared to the given compare value.
func (eg *expressionGenerator) generateWithShortCircuiting(expr codedom.Expression, resultName string, compareValue codedom.Expression, context generationContext) esbuilder.ExpressionBuilder {
	shortCircuiter := eg.generateExpression(
		codedom.RuntimeFunctionCall(codedom.ShortCircuitPromiseFunction,
			[]codedom.Expression{codedom.LocalReference(resultName, expr.BasisNode()), compareValue},
			expr.BasisNode()),
		context)

	return eg.generateExpression(expr, generationContext{shortCircuiter})
}
示例#2
0
func (eg *expressionGenerator) generateShortCircuiter(compareExpr codedom.Expression,
	compareValue codedom.Expression,
	childExpr codedom.Expression,
	context generationContext,
	handler shortCircuitHandler) esbuilder.ExpressionBuilder {

	// Generate a specialized wrapper which resolves the left side value and places it into the result.
	resultName := eg.generateUniqueName("$result")
	resolveCompareValue := codedom.RuntimeFunctionCall(codedom.ResolvePromiseFunction,
		[]codedom.Expression{compareExpr},
		compareExpr.BasisNode())

	eg.addAsyncWrapper(eg.generateExpression(resolveCompareValue, context), resultName)

	shortedChildExpr := eg.generateWithShortCircuiting(childExpr, resultName, compareValue, context)
	return handler(resultName, shortedChildExpr)
}