Why need delay/timeout option of TAWaitWeb.prg
In the TAWaitWeb class, the argument named ‘nSecond’ is present.
Upon closer examination, this argument is not for sleep; instead, it is used to set a waiting time within a while loop to check for changes in the value being passed asynchronously.
Manners maketh man
There is a bold individual who cannot even analyze source code. This person, hiding behind anonymity, asked where the nSecond option is being used and also employed incorrect expressions. However, I do not engage in battles with fools.
So, in summary, nSecond
in this code functions as a timeout value. The method Query
keeps checking for a response in a loop, but it won’t do this indefinitely – it will stop and exit the loop if nSecond
milliseconds have passed without a response. This is a common pattern used to prevent a program from waiting forever in situations where a response might never come, thus avoiding potential hangs or freezes in the application.
Alright, I will show you the relevant code again. Please read it over to understand why the nSecond parameter is necessary…
Code for the wise person.
METHOD Query( cQuery, nSecond, cReturn ) CLASS TAWaitWeb
LOCAL nCounter := 0
LOCAL lReturn := .f.
LOCAL cEval := "SendToFWH($QUERY$, 'WebFunc')"
LOCAL nStartSec := GetTickCount()
DEFAULT nSecond := 500
::bOldBind := ::oWeb:bOnBind
::oWeb:bOnBind := { | cJson, cCalls, ... | ::GetBind( cJson, cCalls, ... ) }
cEval := STRTRAN( cEval, "$QUERY$", cQuery )
::cReturn := ""
WHILE .T.
::oWeb:Eval( cEval )
sleep(100)
SysWait()
IF !EMPTY( ::cReturn )
lReturn := .t.
EXIT
ENDIF
IF GetTickCount() - nStartSec >= nSecond
EXIT
ENDIF
ENDDO
cReturn := ::cReturn
::oWeb:bOnBind := ::bOldBind
RETURN lReturn