1Test2::Harness::Util::QUuseeure(C3o)ntributed Perl DocumTeenstta2t:i:oHnarness::Util::Queue(3)
2
3
4

NAME

6       Test2::Harness::Util::Queue - Representation of a queue.
7

DESCRIPTION

9       This module represents a queue, stored as a jsonl file.
10

SYNOPSIS

12           use Test2::Harness::Util::Queue;
13
14           my $queue = Test2::Harness::Util::Queue->new(file => '/path/to/queue.jsonl');
15
16           $queue->start(); # Create the queue
17
18           $queue->enqueue({foo => 'bar', baz => 'bat'});
19           $queue->enqueue({foo => 'bar2', baz => 'bat2'});
20           ...
21
22           $queue->end();
23
24       Then in another processs:
25
26           use Test2::Harness::Util::Queue;
27
28           my $queue = Test2::Harness::Util::Queue->new(file => '/path/to/queue.jsonl');
29
30           my @items;
31           while (1) {
32               @items = $queue->poll();
33               while (@items) {
34                   my $item = shift @items or last;
35
36                   ... process $item
37               }
38
39               # Queue ends with an 'undef' entry
40               last if @items && !defined($items[0]);
41           }
42

METHODS

44       $path = $queue->file
45           The filename used for the queue
46
47   READING
48       $queue->reset()
49           Restart reading the queue.
50
51       @items = $queue->poll()
52           Get more items from the queue. May need to call it multiple times,
53           specially if another process is still writing to the queue.
54
55           Returns an empty list if no items are available yet.
56
57           Returns 'undef' to terminate the list.
58
59       $bool = $queue->ended()
60           Check if the queue has ended.
61

WRITING

63       $queue->start()
64           Open the queue file for writing.
65
66       $queue->enqueue(\%HASHREF)
67           Add an item to the queue.
68
69       $queue->end()
70           Terminate the queue.
71

SOURCE

73       The source code repository for Test2-Harness can be found at
74       http://github.com/Test-More/Test2-Harness/.
75

MAINTAINERS

77       Chad Granum <exodist@cpan.org>
78

AUTHORS

80       Chad Granum <exodist@cpan.org>
81
83       Copyright 2020 Chad Granum <exodist7@gmail.com>.
84
85       This program is free software; you can redistribute it and/or modify it
86       under the same terms as Perl itself.
87
88       See http://dev.perl.org/licenses/
89
90
91
92perl v5.34.0                      2021-11-05    Test2::Harness::Util::Queue(3)
Impressum