Read from socket async?
Dave Cragg
dcragg at lacscentre.co.uk
Sun Feb 10 08:22:01 EST 2002
At 10:57 pm +1100 10/2/02, David Vaughan wrote:
>Dave
>
>My test and conclusions are valid. Their implication and result is
>that the line I highlighted in your script below will cause your
>repeat loop NEVER to terminate. You see, the message(s) "dataAdded"
>are only queued by the read handler, not executed until the entire
>mouseUp completes. My own script also queues messages in the same
>way, but completes, after which all the queued messages (one for
>each read with data) are then successively run.
Unfair!! It doesn't terminate because I hadn't had coffee and I
didn't have my glasses on. This is what I really typed. :)
on mouseUp
global sname
put zero into lcounter
repeat 10
read from socket sname until return with message "dataAdded"
add 1 to lcounter
put lcounter - 1 into tCounter
wait until tCounter = lcounter with messages ##this is the block
put lcounter into field "f2"
end repeat
end mouseUp
Confession. I didn't set up a socket to test. I used "send .. in"
instead, but the principle is the same. This is what I actually
tested. Try commenting out the "wait ... with messages" line to see
the difference.
local lcounter
on mouseUp
put zero into lcounter
repeat 10
send "dataAdded" to me in 10 milliseconds
add 1 to lcounter
put lcounter
put lcounter -1 into tCounter
wait until tCounter = lCounter with messages ##
end repeat
end mouseUp
on dataAdded
wait for 1 seconds
subtract 1 from lcounter
put lcounter
end dataAdded
Cheers
Dave Cragg
More information about the use-livecode
mailing list