"TheEndless" wrote:"MazeWizzard" wrote:
I still don't know what Wait() is doing for those 10-15 ms
My guess would be that it's doing a GetMessage() loop with a 1ms sleep. That would explain why a Wait(1) and a Sleep(1) produce the same ~10ms delay.
"renojim" wrote:"TheEndless" wrote:"MazeWizzard" wrote:
I still don't know what Wait() is doing for those 10-15 ms
My guess would be that it's doing a GetMessage() loop with a 1ms sleep. That would explain why a Wait(1) and a Sleep(1) produce the same ~10ms delay.
Doesn't Wait() with a non-zero timeout return immediately (give or take) if there's an event pending? That would imply it's not simply doing a Sleep().
-JT
Function Wait(timeout As Integer, port As Object) As Object
If timeout = 0 Then
Return port.GetMessage()
Else
timer = CreateObject("roTimespan")
timer.Mark()
While timer.TotalMilliseconds() < timeout
msg = port.GetMessage()
If msg <> invalid Then
Return msg
End If
Sleep(1)
End While
End If
Return invalid
End Function
"TheEndless" wrote:
I'm not sure I follow...? The first parameter for Wait is the timeout in milliseconds, so my guess it is looks something like this:
Or if WaitMessage has the same strange behavior to wait forever on timeout=0, then just Wait(timeout, port) == port.WaitMessage(timeout)
Function Wait(timeout As Integer, port As Object) As Object
If timeout = 0 Then
Return port.GetMessage()
Else
return port.WaitMessage(timeout)
End If
End Function
- Why does this code check if event is invalid, when it is known that it waits (forever) till a real event comes?!
while True
msg = wait(0, port)
if msg <> invalid then
....
endif
"EnTerr" wrote:
I have a question though - why is it that examples have code like- Why does this code check if event is invalid, when it is known that it waits (forever) till a real event comes?!
while True
msg = wait(0, port)
if msg <> invalid then
....
endif
"belltown" wrote:"EnTerr" wrote:
Why does this code check if event is invalid, when it is known that it waits (forever) till a real event comes?!
I think it's because even in a wait forever loop there are circumstances when an Invalid event may be received, which would normally be considered a timout if a wait time of >0 was specified. For example, pressing the 'Home' key causes a slew of Invalid messages. There's a discussion about that here: http://forums.roku.com/viewtopic.php?f=34&t=31487&hilit=wait+invalid#p193585
"TheEndless" wrote:
I'm not sure I follow...? The first parameter for Wait is the timeout in milliseconds, so my guess it is looks something like this: (clipped)
"renojim" wrote:
I think the interesting part of this discussion is the undocumented port.GetMessage() function. I wonder how many other really useful undocumented functions there are.
roMessagePort GetMessage (Void)- with a note "When using BrightScript, you would not call these functions directly. Instead, use the “Wait” BrightScript statement"
roMessagePort WaitMessage(Integer timeout)
"EnTerr" wrote:
It's documented - pg.90 of component reference,
"EnTerr" wrote:
Hmmmm... is it just me, or is this interface wrong? Those two methods do not return "roMessagePort", they return "roMessage***Event"