Test2:...::Queue(3pm)

πŸ’– Test2::Harness::Util::Queue πŸ’–

okay bestie, gather round, because this one is genuinely so cute once you get it. this is Test2::Harness::Util::Queue, a little Perl module that lives in the Test2 family (you'll see it filed under Test2:...::Queue in the manual pages, dw about it) πŸŽ€


✨ NAME ✨

Test2::Harness::Util::Queue β€” no cap, it's literally just a representation of a queue. that's the whole vibe. πŸ’…


🌸 DESCRIPTION 🌸

so basically: this module represents a queue, and it stores that queue as a jsonl file. that's it, that's the tea. one queue, one file, lines of json, slay. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole flow, bestie. first you make the queue:

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();

and then, plot twist, in another process (yes, another process, she's built for that πŸ’€):

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

iconic. writer on one side, reader on the other, undef as the little goodbye wave. 🫢


πŸ‘‘ METHODS πŸ‘‘

  • $path = $queue->file β€” hands you back the filename that's being used for the queue. the receipts, the address, the whole location. πŸ“

πŸ“– READING πŸ“–

  • $queue->reset() β€” restart reading the queue. like, from the top, bestie. rewind button energy. βͺ
  • @items = $queue->poll() β€” grab more items out of the queue. ngl you might have to call this one multiple times, specially if another process is still writing to the queue (she's streaming, not snapshotting, iykyk).
    • returns an empty list if no items are available yet. not a problem, just not yet. πŸ•
    • returns 'undef' to terminate the list. that's the end-of-queue bat signal. πŸ¦‡
  • $bool = $queue->ended() β€” check if the queue has ended. just a lil boolean vibe check. βœ…

✍️ WRITING ✍️

  • $queue->start() β€” open the queue file for writing. the pen is officially in your hand. βœ’οΈ
  • $queue->enqueue(\%HASHREF) β€” add an item to the queue. got a hashref? she's in the queue now. periodt. πŸ“
  • $queue->end() β€” terminate the queue. wrap it up, we're done here, lights off. πŸŒ™

🌈 SOURCE 🌈

the source code repository for Test2-Harness can be found at http://github.com/Test-More/Test2-Harness/. go snoop, bestie, it's public. πŸ‘€


πŸ’œ MAINTAINERS πŸ’œ

Chad Granum <exodist@cpan.org>


⭐ AUTHORS ⭐

Chad Granum <exodist@cpan.org>


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/


and that's the whole page, bestie!! this was documented with perl v5.40.1 and dated 2026-05-10, and honestly? iconic of it. go build a queue, you're gonna ate. πŸ’…βœ¨πŸ‘‘

πŸ“¦ where this page comes from