Test2::Harness::Util::Queue - Representation of a queue.
This module represents a queue, stored as a jsonl file.
use Test2::Harness::Util::Queue; my $queue = Test2::Harness::Util::Queue->new(file => '/path/to/queue.jsonl'); $queue->start(); # Create the queue $queue->enqueue({foo => 'bar', baz => 'bat'}); $queue->enqueue({foo => 'bar2', baz => 'bat2'}); ... $queue->end();
Then in another processs:
use Test2::Harness::Util::Queue; my $queue = Test2::Harness::Util::Queue->new(file => '/path/to/queue.jsonl'); my @items; while (1) { @items = $queue->poll(); while (@items) { my $item = shift @items or last; ... process $item } # Queue ends with an 'undef' entry last if @items && !defined($items[0]); }
The filename used for the queue
Restart reading the queue.
Get more items from the queue. May need to call it multiple times, specially if another process is still writing to the queue.
Returns an empty list if no items are available yet.
Returns 'undef' to terminate the list.
Check if the queue has ended.
Open the queue file for writing.
Add an item to the queue.
Terminate the queue.
The source code repository for Test2-Harness can be found at http://github.com/Test-More/Test2-Harness/.
Copyright 2020 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
To install Test2::Harness, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test2::Harness
CPAN shell
perl -MCPAN -e shell install Test2::Harness
For more information on module installation, please visit the detailed CPAN module installation guide.