RE: Question on design

From: <>
Date: Wed, 1 Jun 2005 11:39:47 -0400

Hi Vadim

This helped me a lot! The code example you used below EXACTLY describes one
of the thing I need to do: present a progress bar to the user.

Thanks VERY much for taking the time to write this!


-----Original Message-----
From: Vadim Belman []
Sent: Wednesday, June 01, 2005 4:22 AM
Subject: Re: Question on design wrote:

> Thanks very much for the reply, and the suggestion. I've been
> with $::application->yield();, and have achieved some different
> But the application still isn't working as I'd like.
> Where should I place the '$::application->yield();' line, and how many of
> them do I need?

A simple answer would be: call it as many times as possible. This will
make your application behave smoothly.

More complicated answer would include some considerable amount of
explanations. 8) Since we're talking about design here, let's get a
little bit deeper into it.

First of all, we shall postulate the fact that any Prima based
application is an interactive one. It must respond to user actions as
well as to system requests (like repainting a widget, for instance).
Getting back to the event processing, this means that Prima must be able
to accept and properly process all kind of events as soon as they're arisen.

Obviously, any time your program executes statements like

$str = <FILE>;

it blocks until certain amount of data is received. No event processing
is done over this time - perl is busy waiting for data.

There are two most common ways to overcome the problem. One is to use
threads, which isn't acceptable for perl (threads are just nothing more
but a headache).

The other one is to use non-blocking i/o. This is where Prima::File
comes to help. With this class you wouldn't even have to use yield()
method as all the processing would be done for you automatically.

yield() becomes useful if one needs to do some massive data processing,
for instance. Especially if intermediate results or progress are to be
displayed to user. In this case yield() is to be called any time a
widget has been updated. For example, we have a Prima::Gauge widget in a
window $w:

for (...) { # Some looooong loop
        ... # Here we do a lot of calculations, data moving, etc.
        $w->SomeLabel->text("$percent\% done");

There could also be cases when you use third-party modules where some
calls takes long time to complete (like LWP::UserAgent::get(), for
example). If there is callback support implemented, I'd recommend using
it. Your callback code would contain same code as in the last example.

So, these are the must-follow principles as I see them.

			/Vadim Belman
Received on Wed 01 Jun 2005 - 17:40:07 CEST

This archive was generated by hypermail 2.2.0 : Sat 19 Mar 2011 - 18:35:05 CET