Hi lanas!
On 27 Sep 05 at 23:13, "lanas" (lanas ) wrote:
lanas> Now, if several such tasks are to be performed in sequence, what
lanas> approach would you recommend ? As far as I can see there are the
lanas> Prima::Timer which looks like a crude approach but could
lanas> nevertheless work I think, and there's the Prima::EventHook about
lanas> which I there are no examples in the Prima example files.
I don't think Timer is needed here. Whenever you detect a EOF, you assume
that a process is finished and start a next one. For example:
sub feed_batch
{
close F;
return unless $_ = shift @batch;
open F, "$_|" or die $!;
\*F;
}
Prima::File-> new(
file => feed_batch,
onRead => sub {
my $buffer;
my $read = sysread( $_[0]-> file, $buffer, 512);
if ( defined $read and $read > 0) {
# do something with $buffer
} elsif ( !defined $read) {
# signal an error
} else {
# assume a process is finished, start a new one
$_[0]-> file( feed_batch);
}
} );
This is crude, but I think should be illustrative enough.
lanas> But then the Prima::EventHook interface looks very interesting.
lanas> Is it possible to create our own events and is it possible to set
lanas> them in one way or another and expect the 'callback' (i.e. state
lanas> manager) to immediately react upon ? How does it work exactly, any
lanas> examples around ?
Yes, it is definitely possible to create our own events, it is done by
overloading the ::notification_types method. All of these events are
synchronous though; this means that you don't really need the event
dispatcher to signal anything you trigger yourself, a simple callback sub
would be enough. If you need asychnronous event dispatching, there is
onPostMessage, that is called after ::post_message.
There's no examples on EventHook, but there's short pod section in the
module, try perldoc Prima::EventHook.
-- HTH, Dmitry KarasikReceived on Wed 28 Sep 2005 - 10:33:43 CEST
This archive was generated by hypermail 2.2.0 : Sat 19 Mar 2011 - 18:35:06 CET