NAME

Future::Batch::XS - Full XS batch processing for Future operations

VERSION

Version 0.01

SYNOPSIS

use Future::Batch::XS qw(batch);

my $results = batch(
    items      => \@urls,
    concurrent => 5,
    worker     => sub {
        my ($url, $index) = @_;
        return $http->GET($url);
    },
)->get;

DESCRIPTION

Future::Batch::XS provides a complete XS implementation of batch processing for Future operations. Unlike typical XS modules that wrap Perl code, this module implements the entire batch processing loop in C/XS.

Key features:

  • 100% XS implementation - no Perl code in the hot path

  • Batch state stored in C struct with SV magic

  • XS closures for Future callbacks using CvXSUBANY

  • Memory-efficient callback data management

  • Full async support via IO::Async::Loop

METHODS

new

my $batch = Future::Batch::XS->new(%options);

Constructor. Options:

  • concurrent - Maximum concurrent operations (default: 10)

  • fail_fast - Stop on first failure (default: false)

  • on_progress - Progress callback coderef

  • loop - IO::Async::Loop for async scheduling

run

my $future = $batch->run(items => \@items, worker => \&worker);

Execute batch processing. Returns a Future.

concurrent

my $n = $batch->concurrent;
$batch->concurrent(20);

Get/set maximum concurrent operations.

fail_fast

my $ff = $batch->fail_fast;
$batch->fail_fast(1);

Get/set fail-fast mode.

on_progress

$batch->on_progress(sub { my ($done, $total) = @_; ... });

Get/set progress callback.

loop

$batch->loop($loop);

Get/set IO::Async::Loop.

FUNCTIONS

batch

my $future = batch(
    items      => \@items,
    worker     => \&worker,
    concurrent => 5,
);

Functional interface combining new() and run().

IMPLEMENTATION NOTES

This module creates XS closures for Future's on_done/on_fail callbacks. Each callback stores its closure data (state reference, item, index) in a C struct attached to the CV via SV magic (PERL_MAGIC_ext).

The callback data is automatically freed when the CV is garbage collected.

SEE ALSO

Future::Batch, Future, Future::XS

AUTHOR

Your Name <your@email.com>

LICENSE

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.