.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test2::Harness::Util::Queue 3pm" .TH Test2::Harness::Util::Queue 3pm 2024-03-08 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Test2::Harness::Util::Queue \- Representation of a queue. .SH DESCRIPTION .IX Header "DESCRIPTION" This module represents a queue, stored as a jsonl file. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Test2::Harness::Util::Queue; \& \& my $queue = Test2::Harness::Util::Queue\->new(file => \*(Aq/path/to/queue.jsonl\*(Aq); \& \& $queue\->start(); # Create the queue \& \& $queue\->enqueue({foo => \*(Aqbar\*(Aq, baz => \*(Aqbat\*(Aq}); \& $queue\->enqueue({foo => \*(Aqbar2\*(Aq, baz => \*(Aqbat2\*(Aq}); \& ... \& \& $queue\->end(); .Ve .PP Then in another processs: .PP .Vb 1 \& use Test2::Harness::Util::Queue; \& \& my $queue = Test2::Harness::Util::Queue\->new(file => \*(Aq/path/to/queue.jsonl\*(Aq); \& \& my @items; \& while (1) { \& @items = $queue\->poll(); \& while (@items) { \& my $item = shift @items or last; \& \& ... process $item \& } \& \& # Queue ends with an \*(Aqundef\*(Aq entry \& last if @items && !defined($items[0]); \& } .Ve .SH METHODS .IX Header "METHODS" .ie n .IP "$path = $queue\->file" 4 .el .IP "\f(CW$path\fR = \f(CW$queue\fR\->file" 4 .IX Item "$path = $queue->file" The filename used for the queue .SS READING .IX Subsection "READING" .ie n .IP $queue\->\fBreset()\fR 4 .el .IP \f(CW$queue\fR\->\fBreset()\fR 4 .IX Item "$queue->reset()" Restart reading the queue. .ie n .IP "@items = $queue\->\fBpoll()\fR" 4 .el .IP "\f(CW@items\fR = \f(CW$queue\fR\->\fBpoll()\fR" 4 .IX Item "@items = $queue->poll()" Get more items from the queue. May need to call it multiple times, specially if another process is still writing to the queue. .Sp Returns an empty list if no items are available yet. .Sp Returns 'undef' to terminate the list. .ie n .IP "$bool = $queue\->\fBended()\fR" 4 .el .IP "\f(CW$bool\fR = \f(CW$queue\fR\->\fBended()\fR" 4 .IX Item "$bool = $queue->ended()" Check if the queue has ended. .SH WRITING .IX Header "WRITING" .ie n .IP $queue\->\fBstart()\fR 4 .el .IP \f(CW$queue\fR\->\fBstart()\fR 4 .IX Item "$queue->start()" Open the queue file for writing. .ie n .IP $queue\->enqueue(\e%HASHREF) 4 .el .IP \f(CW$queue\fR\->enqueue(\e%HASHREF) 4 .IX Item "$queue->enqueue(%HASHREF)" Add an item to the queue. .ie n .IP $queue\->\fBend()\fR 4 .el .IP \f(CW$queue\fR\->\fBend()\fR 4 .IX Item "$queue->end()" Terminate the queue. .SH SOURCE .IX Header "SOURCE" The source code repository for Test2\-Harness can be found at \&\fIhttp://github.com/Test\-More/Test2\-Harness/\fR. .SH MAINTAINERS .IX Header "MAINTAINERS" .IP "Chad Granum " 4 .IX Item "Chad Granum " .SH AUTHORS .IX Header "AUTHORS" .PD 0 .IP "Chad Granum " 4 .IX Item "Chad Granum " .PD .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2020 Chad Granum . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See \fIhttp://dev.perl.org/licenses/\fR