Test2::Harness::Util::Queue(3pm)

Test2::Harness::Util::Queue3pm

Representation of a queue.

Usage

    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]);
    }

Overview

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

Methods

$path = $queue->file

The filename used for the queue

Reading

$queue->reset()

Restart reading the queue.

@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.

Returns an empty list if no items are available yet.

Returns 'undef' to terminate the list.

$bool = $queue->ended()

Check if the queue has ended.

Writing

$queue->start()

Open the queue file for writing.

$queue->enqueue(\%HASHREF)

Add an item to the queue.

$queue->end()

Terminate the queue.

Source

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

Maintainers

Chad Granum <[email protected]>

Releases

2 releases since Debian 12 (Bookworm); the text changed 1 time.

  1. 12
  2. 13

Authors

Chad Granum <[email protected]>

From libtest2-harness-perl 1.000158-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.