Ekorn-Pipeline-Futures
Stages for Ekorn::Pipeline that wait on Futures and promises: many requests at once, in one process, beside the call.
A function that takes stages from its caller, as Ekorn::Pipeline's do, runs each value it hands out through them, one at a time. When what a caller wants done with each value is to wait on the network, for a page, a REST call or a query, one at a time is slow. in_futures lets the caller keep many in flight, with nothing of the function changed:
use v5.36;
use Mojo::Base -strict, -async_await;
use Mojo::UserAgent;
use Ekorn::Pipeline;
use Ekorn::Pipeline::Futures qw(in_futures);
my $ua = Mojo::UserAgent->new;
my @urls = map {"https://example.com/page/$_"} 1 .. 100;
# Twenty pages at a time, given in the order the URLs came.
my @pages = Ekorn::Pipeline->new(
in_futures(20, async sub ($url) {
my $tx = await $ua->get_p($url);
return {url => $url, status => $tx->result->code};
}),
)->(@urls);
This, Workers, or neither?
Ekorn::Pipeline has two distributions for doing many things at once. Which fits depends on what each value's work waits for:
Waiting on I/O a library can do asynchronously, giving Futures or promises, as Mojo::UserAgent and IO::Async do: this one. One process waits on many requests at once.
Work that blocks, as the DBI's does, or a module's with only a synchronous interface; or work for the CPU: Ekorn::Pipeline::Workers. Each value's work runs in a worker, a perl of its own, so it's a function in a module.
Neither, as each value's work takes microseconds: an ordinary stage.
What it does
Any loop
awaitknows. A block gives a Future, such as IO::Async's, or a Mojo::Promise, as Mojo::UserAgent'sget_pdoes: whatever Future::AsyncAwait'sawaittakes. The stage names no loop.In order, or as they're ready.
in_futurespasses results on in the order the values came;in_futures_as_ready, as each is.Where each result came from. The stages after it see each result's own original, as Ekorn::Pipeline v0.5.0 lets a stage that holds values back say.
Failures and stops in their turn, and a stop after it cancels what's in flight, where it can be: a Future is cancelled, and a Mojo::Promise, which can't be, is left to settle.
On Windows too. Nothing forks; the tests, and every recipe in the user guide, run on Linux, macOS and Windows.
What it isn't for
It's for programs that run no loop of their own: scripts, batch jobs, scrapers and command-line tools. A pipeline's run is synchronous, so don't run these stages inside a callback of a loop that's already running, such as a Mojolicious app's request handler.
Documentation
Ekorn::Pipeline::Futures::Manual::HowTo, the user guide, is the place to start: recipes, each a whole program, tested as it stands. Ekorn::Pipeline::Futures::Manual::Reference says what the stages promise, at length, each promise linked to the recipes that show it. Ekorn::Pipeline::Futures says the same briefly, and is the authority where they differ.
Installing
cpanm Ekorn::Pipeline::Futures
It needs Perl 5.36 or later, Ekorn::Pipeline v0.5.x and Future. The loops and clients a block uses are the caller's to install.
Licence
Copyright (c) 2026 by Iain Campbell. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Acknowledgements
Designed and created by Iain Campbell, in collaboration with Claude, Anthropic's AI model.