On Sep 7, 9:36 pm, "Gordon Rahman" <grah...@[EMAIL PROTECTED]
> wrote:
> I can just WAIT anywhere in my program. Waiting for an event.
Liberty Basic's SCAN/WAIT method of handling events is interesting,
because it forces events to be synchronous, i.e. they can only happen
when you explicitly allow them to happen (by executing SCAN or WAIT).
This eliminates many of the pitfalls associated with truly
asynchronous events. In fact WAIT is not all that different from
sitting in a polling loop from which you can only exit when an event
occurs, except that you don't have to bother to code the waiting loop
yourself.
The disadvantage of the SCAN/WAIT method is, of course, is that you
must explicitly place a SCAN or WAIT statement anywhere in your
program where you might want it to respond to an event. If your
program is performing some complex operation, and you want it to
respond in a timely fa****on to an external event, you may have to
place SCAN statements in many places.
I've also wondered what happens in Liberty Basic if two or more events
happen before the next SCAN or WAIT statement is executed. Do they
get queued, or does only the most recent event get recognised?
BBC BASIC for Windows sup****ts truly asynchrononous events, which can
interrupt execution of the program whatever it may be doing. This is
potentially more powerful, because it doesn't require existing code to
be modified, and can be arranged not to 'lose' any events. Latency is
also potentially reduced. However it does introduce difficulties of
concurrency because you typically don't have any idea what the program
is doing when the event occurs, and an event handler can itself be
interrupted by another event.
That's why I often prefer the event handler simply to set a global
flag, because then I can reproduce Liberty Basic's simpler behavior,
when that is acceptable. Effectively BBC BASIC gives the programmer
the best of both worlds: truly asynchronous events when he needs them
and synchronous events when he doesn't.
Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.


|