@@ -30,9 +30,10 @@ public void RunDeferred(
30
30
{
31
31
var newTask = new DeferredTask ( )
32
32
{
33
- ConditionAction = ( task ) => task . TickCount >= task . FrameTarget ,
33
+ ConditionAction = ( task ) => task . TickCount >= task . StartFrame ,
34
34
CompleteAction = action ,
35
- FrameTarget = delay ,
35
+ MaxFrames = delay ,
36
+ StartFrame = delay ,
36
37
DebugPath = $ "{ callerFile } :{ callerLine } - { callerMember } "
37
38
} ;
38
39
@@ -42,7 +43,9 @@ public void RunDeferred(
42
43
public void RunUntilSatisfied (
43
44
Func < bool > condition ,
44
45
Action < bool > onSatisfied ,
45
- int attempts = 0 ,
46
+ int attempts ,
47
+ int dontStartFor = 0 ,
48
+ bool waitOneMore = false ,
46
49
[ CallerFilePath ] string callerFile = "" ,
47
50
[ CallerLineNumber ] int callerLine = 0 ,
48
51
[ CallerMemberName ] string callerMember = ""
@@ -52,7 +55,9 @@ public void RunUntilSatisfied(
52
55
{
53
56
ConditionAction = ( _ ) => condition . Invoke ( ) ,
54
57
CompleteAction = onSatisfied . Invoke ,
55
- FrameTarget = attempts ,
58
+ MaxFrames = attempts ,
59
+ StartFrame = dontStartFor ,
60
+ DeferOnceMore = waitOneMore ,
56
61
DebugPath = $ "{ callerFile } :{ callerLine } - { callerMember } "
57
62
} ;
58
63
@@ -72,20 +77,31 @@ private void TickTasks()
72
77
var task = _deferredTasks [ i ] ;
73
78
task . TickCount ++ ;
74
79
75
- var conditionSatisfied = CheckTask ( task ) ;
76
-
77
- if ( conditionSatisfied == true )
78
- {
79
- _deferredTasks . RemoveAt ( i -- ) ;
80
- CompleteTask ( task , true ) ;
81
- }
82
- else if ( conditionSatisfied == null || task . FrameTarget <= task . TickCount )
80
+ if ( task . TickCount >= task . StartFrame )
83
81
{
84
- if ( task . FrameTarget <= task . TickCount )
85
- PluginLog . Warning ( $ "Task timed out. { task } ") ;
86
-
87
- _deferredTasks . RemoveAt ( i -- ) ;
88
- CompleteTask ( task , false ) ;
82
+ var conditionSatisfied = CheckTask ( task ) ;
83
+
84
+ if ( conditionSatisfied == true )
85
+ {
86
+ if ( task . DeferOnceMore )
87
+ {
88
+ task . DeferOnceMore = false ;
89
+ task . ConditionAction = ( _ ) => true ;
90
+ }
91
+ else
92
+ {
93
+ _deferredTasks . RemoveAt ( i -- ) ;
94
+ CompleteTask ( task , true ) ;
95
+ }
96
+ }
97
+ else if ( conditionSatisfied == null || task . MaxFrames <= task . TickCount )
98
+ {
99
+ if ( task . MaxFrames <= task . TickCount )
100
+ PluginLog . Warning ( $ "Task timed out. { task } ") ;
101
+
102
+ _deferredTasks . RemoveAt ( i -- ) ;
103
+ CompleteTask ( task , false ) ;
104
+ }
89
105
}
90
106
}
91
107
}
@@ -117,11 +133,13 @@ private void CompleteTask(DeferredTask task, bool success)
117
133
118
134
class DeferredTask
119
135
{
120
- public Func < DeferredTask , bool > ConditionAction { get ; init ; } = null ! ;
121
- public Action < bool > CompleteAction { get ; init ; } = null ! ;
122
- public string DebugPath { get ; init ; } = null ! ;
123
- public int FrameTarget { get ; init ; }
136
+ public Func < DeferredTask , bool > ConditionAction { get ; set ; } = null ! ;
137
+ public Action < bool > CompleteAction { get ; set ; } = null ! ;
138
+ public string DebugPath { get ; set ; } = null ! ;
139
+ public int MaxFrames { get ; set ; }
140
+ public int StartFrame { get ; set ; }
124
141
public int TickCount { get ; set ; } = - 1 ;
142
+ public bool DeferOnceMore { get ; set ; } = false ;
125
143
126
- public override string ToString ( ) => $ "{ DebugPath } . T: { FrameTarget } C: { TickCount } ";
144
+ public override string ToString ( ) => $ "{ DebugPath } . T: { MaxFrames } C: { TickCount } ";
127
145
}
0 commit comments