@@ -38,6 +38,22 @@ func (c *WaitCompiler) tryCompileWaitPredicateFastPath(config waitPredicateCompi
3838 return c .emitImmediateWaitBool (false ), true
3939 }
4040
41+ return bytecode .NoopOperand , false
42+ case waitForPredicateModeValue :
43+ present , ok := literalPresentFromExpression (config .predExpr )
44+ if ! ok {
45+ return bytecode .NoopOperand , false
46+ }
47+
48+ if present {
49+ return c .exprs .Compile (config .predExpr ), true
50+ }
51+
52+ if config .timeoutReg != bytecode .NoopOperand {
53+ c .ctx .Program .Emitter .EmitA (bytecode .OpSleep , config .timeoutReg )
54+ return c .emitImmediateWaitNone (), true
55+ }
56+
4157 return bytecode .NoopOperand , false
4258 default :
4359 exists , ok := literalExistsFromExpression (config .predExpr )
@@ -51,19 +67,11 @@ func (c *WaitCompiler) tryCompileWaitPredicateFastPath(config waitPredicateCompi
5167 }
5268
5369 if cond {
54- if config .mode == waitForPredicateModeValue {
55- return c .exprs .Compile (config .predExpr ), true
56- }
57-
5870 return c .emitImmediateWaitBool (true ), true
5971 }
6072
6173 if config .timeoutReg != bytecode .NoopOperand {
6274 c .ctx .Program .Emitter .EmitA (bytecode .OpSleep , config .timeoutReg )
63- if config .mode == waitForPredicateModeValue {
64- return c .emitImmediateWaitNone (), true
65- }
66-
6775 return c .emitImmediateWaitBool (false ), true
6876 }
6977
@@ -160,16 +168,24 @@ func (c *WaitCompiler) emitWaitPredicatePollIteration(
160168 startLabel , successLabel , timeoutLabel core.Label ,
161169) bytecode.Operand {
162170 valueReg := c .exprs .Compile (config .predExpr )
163- condReg := c .emitWaitPredicateCondition (config .mode , valueReg )
164-
165- if len (config .whenExprs ) == 0 {
166- c .ctx .Program .Emitter .EmitJumpIfTrue (condReg , successLabel )
167- } else {
171+ if config .mode == waitForPredicateModeValue {
168172 retryLabel := c .ctx .Program .Emitter .NewLabel ()
169- c .ctx .Program .Emitter .EmitJumpIfFalse ( condReg , retryLabel )
173+ c .ctx .Program .Emitter .EmitJumpIfNone ( valueReg , retryLabel )
170174 c .emitWaitPredicateWhenConditions (config , valueReg , retryLabel )
171175 c .ctx .Program .Emitter .EmitJump (successLabel )
172176 c .ctx .Program .Emitter .MarkLabel (retryLabel )
177+ } else {
178+ condReg := c .emitWaitPredicateCondition (config .mode , valueReg )
179+
180+ if len (config .whenExprs ) == 0 {
181+ c .ctx .Program .Emitter .EmitJumpIfTrue (condReg , successLabel )
182+ } else {
183+ retryLabel := c .ctx .Program .Emitter .NewLabel ()
184+ c .ctx .Program .Emitter .EmitJumpIfFalse (condReg , retryLabel )
185+ c .emitWaitPredicateWhenConditions (config , valueReg , retryLabel )
186+ c .ctx .Program .Emitter .EmitJump (successLabel )
187+ c .ctx .Program .Emitter .MarkLabel (retryLabel )
188+ }
173189 }
174190
175191 elapsedReg := c .emitWaitPredicateTimeoutCheck (config .timeoutReg , state .startReg , state .unitReg , timeoutLabel )
@@ -210,7 +226,7 @@ func (c *WaitCompiler) emitWaitPredicateWhenConditions(
210226
211227func (c * WaitCompiler ) emitWaitPredicateCondition (mode waitForPredicateMode , valueReg bytecode.Operand ) bytecode.Operand {
212228 switch mode {
213- case waitForPredicateModeValue , waitForPredicateModeExists :
229+ case waitForPredicateModeExists :
214230 return c .emitExistsCheck (valueReg )
215231 case waitForPredicateModeNotExists :
216232 existsReg := c .emitExistsCheck (valueReg )
0 commit comments