On Wed, Dec 25, 2013 at 11:34:26AM -0500, Paul Evans via RT wrote:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=91648 >
>
> On Wed Dec 25 03:32:06 2013, DRRHO wrote:
> > I strongly miss a way to determine whether a channel has messages
> > in it. ->recv in sync mode will block, but there are situations where
> > you want to check the channel, and if there is nothing in it, you move
> > on with your life.
Show quoted text> Hmm. The question I suppose is how to handle the message reading
> properly, because you can't just atomically read() an entire
> message.
Yes, that does not fit nicely into the async programming paradigm.
Show quoted text> At which point we're starting to rebuild a micro event system on the
> Routine side of the Channel. I start to wonder whether in your case,
> your program may be better served by running another IO::Async::Loop
> within the child process side.
Unfortunately that is not an option (recursive structure).
Show quoted text> What's the use-case surrounding this? This doesn't sound like the
> simple kind of Channel+Routine used to asynchronise some kind of
> synchronous function call. Perhaps something larger may help here..?
Use case is task scheduling: I have a scheduler which runs large
computations in an optimized order. In-between the transitions
the web server should serve any outstanding requests.
In a nutshell I want something like this:
sub _compute_when_idle {
my $code = shift;
my $fu = $loop->new_future;
my $co = sub { &$code () ; $fu->done };
$loop->later ( $co );
$loop->await ($fu);
}
map { my $id = $_;
_compute_when_idle ( sub { warn "long synchronous computation $id"; sleep 2; } )
} ( 'aaa', 'bbbb', 'ccccccc', 'ddddd' ); # transitions
This actually works if there is only a timer in the $loop:
# create $timer
$loop->add( $timer );
But ->later seems to completely ignore incoming HTTP when
# create $httpserver
$loop->add( $httpserver );
is added instead.
\rho
PS: I cannot fork() as transitions are transactional on a larger in-memory structure.