Subject: | Enhancement suggestion: simple priority for IO::Async::Function calls |
Very simple, 2-level priority control, please see patch file.
Subject: | priority.patch |
--- Function.pm.orig Wed Jun 12 18:57:20 2019
+++ Function.pm Wed Jun 26 13:19:58 2019
@@ -55,10 +55,11 @@
The object represents the function code itself, rather than one specific
invocation of it. It can be called multiple times, by the C<call> method.
Multiple outstanding invocations can be called; they will be dispatched in
-the order they were queued. If only one worker process is used then results
-will be returned in the order they were called. If multiple are used, then
-each request will be sent in the order called, but timing differences between
-each worker may mean results are returned in a different order.
+the order they were queued; C<urgent> parameter, if supplied, determines call
+placement at start or end of queue. If only one worker process is used then
+results will be returned in the order they were queued. If multiple are used,
+then each request will be sent in the order queued, but timing differences
+between each worker may mean results are returned in a different order.
Since the code block will be called multiple times within the same child
process, it must take care not to modify any of its state that might affect
@@ -329,6 +330,10 @@
A reference to the array of arguments to pass to the code.
+=item urgent => BOOL
+
+Optional. If true, call is placed at start of queue.
+
=back
If the function body returns normally the list of results are provided as the
@@ -403,6 +408,8 @@
my $args = delete $params{args};
ref $args eq "ARRAY" or croak "Expected 'args' to be an array";
+
+ my $urgent = delete $params{urgent};
my ( $on_done, $on_fail );
if( defined $params{on_result} ) {
@@ -440,7 +447,9 @@
}
else {
$self->debug_printf( "QUEUE" );
- push @{ $self->{pending_queue} }, my $wait_f = $self->loop->new_future;
+ my $wait_f = $self->loop->new_future;
+ $urgent ? unshift @{ $self->{pending_queue} }, $wait_f
+ : push @{ $self->{pending_queue} }, $wait_f;
$future = $wait_f->then( sub {
my ( $self, $worker ) = @_;