1Mojo::IOLoop::ReadWriteUPsreorceCsosn:t:rQiubeuuteeM(do3jpPome:)r:lIODLoocoupm:e:nRteaatdiWorniteProcess::Queue(3pm)
2
3
4
6 Mojo::IOLoop::ReadWriteProcess::Queue - Queue for
7 Mojo::IOLoop::ReadWriteProcess objects.
8
10 use Mojo::IOLoop::ReadWriteProcess qw(queue process);
11 my $n_proc = 20;
12 my $fired;
13
14 my $q = queue;
15
16 $q->pool->maximum_processes(2); # Max 2 processes in parallel
17 $q->queue->maximum_processes(10); # Max queue is 10
18
19 $q->add( process sub { return 42 } ) for 1..7;
20
21 # Subscribe to all "stop" events in the pool
22 $q->once(stop => sub { $fired++; });
23
24 # Consume the queue
25 $q->consume();
26
27 my $all = $q->done; # All processes, Mojo::Collection of Mojo::IOLoop::ReadWriteProcess
28
29 # Set your own running pool
30 $q->pool(parallel sub { return 42 } => 5);
31
32 # Set your own queue
33 $q->queue(parallel sub { return 42 } => 20);
34
35 $q->consume();
36
38 Mojo::IOLoop::ReadWriteProcess::Queue inherits all methods from
39 Mojo::Base and implements the following new ones. Note: It proxies all
40 the other methods of Mojo::IOLoop::ReadWriteProcess for the whole
41 process group.
42
43 add
44 use Mojo::IOLoop::ReadWriteProcess qw(queue process);
45 my $q = queue();
46 $q->add(sub { print "Hello 2! " });
47 $q->add(process sub { print "Hello 2! " });
48
49 Add the process to the queue.
50
51 consume
52 use Mojo::IOLoop::ReadWriteProcess qw(queue);
53 my $q = queue();
54 $q->add(sub { print "Hello 2! " });
55 $q->add(process sub { print "Hello 2! " });
56 $q->consume; # executes and exhaust the processes
57
58 Starts the processes and empties the queue. Note: maximum_processes
59 can be set both to the pool (number of process to be run in parallel),
60 and for the queue (that gets exhausted during the consume() phase).
61
62 $q->pool->maximum_processes(2); # Max 2 processes in parallel
63 $q->queue->maximum_processes(10); # Max queue is 10
64
65 exhausted
66 use Mojo::IOLoop::ReadWriteProcess qw(queue);
67 my $q = queue();
68 $q->add(sub { print "Hello 2! " });
69 $q->add(process sub { print "Hello 2! " });
70 $q->consume; # executes and exhaust the processes
71 $q->exhausted; # 1
72
73 Returns 1 if the queue is exhausted.
74
76 You can set the MOJO_PROCESS_MAXIMUM_PROCESSES environment variable to
77 specify the the maximum number of processes allowed in the pool and the
78 queue, that are Mojo::IOLoop::ReadWriteProcess::Pool instances.
79
80 MOJO_PROCESS_MAXIMUM_PROCESSES=10000
81
83 Copyright (C) Ettore Di Giacinto.
84
85 This library is free software; you can redistribute it and/or modify it
86 under the same terms as Perl itself.
87
89 Ettore Di Giacinto <edigiacinto@suse.com>
90
91
92
93perl v5.38.0 202M3o-j0o9:-:2I4OLoop::ReadWriteProcess::Queue(3pm)