Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mark-5/p5-broker-async
Broker tasks for multiple workers
https://github.com/mark-5/p5-broker-async
perl
Last synced: about 1 month ago
JSON representation
Broker tasks for multiple workers
- Host: GitHub
- URL: https://github.com/mark-5/p5-broker-async
- Owner: mark-5
- Created: 2016-10-26T03:56:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-14T00:57:11.000Z (over 7 years ago)
- Last Synced: 2023-08-20T22:54:11.070Z (over 1 year ago)
- Topics: perl
- Language: Perl
- Homepage: https://metacpan.org/pod/Broker::Async
- Size: 57.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
Awesome Lists containing this project
README
# NAME
Broker::Async - broker tasks for multiple workers
# SYNOPSIS
my @workers;
for my $uri (@uris) {
my $client = SomeClient->new($uri);
push @workers, sub { $client->request(@_) };
}my $broker = Broker::Async->new(@workers);
for my $future (map $broker->do($_), @requests) {
my $result = $future->get;
...
}# DESCRIPTION
This module brokers tasks for multiple asynchronous workers. A worker can be any code reference that returns a [Future](https://metacpan.org/pod/Future), representing work awaiting completion.
Some common use cases include throttling asynchronous requests to a server, or delegating tasks to a limited number of processes.
# METHODS
## new
my @args = ( sub { ... }, ... );
my $broker = Broker::Async->new(@args);@args must be an array of workers used for handling tasks.
Can be a code reference, a hash ref of [Broker::Async::Worker](https://metacpan.org/pod/Broker::Async::Worker) arguments, or a [Broker::Async::Worker](https://metacpan.org/pod/Broker::Async::Worker) object.
Every invocation of a worker must return a [Future](https://metacpan.org/pod/Future) object.Under the hood, code and hash references are simply used to instantiate a [Broker::Async::Worker](https://metacpan.org/pod/Broker::Async::Worker) object.
See [Broker::Async::Worker](https://metacpan.org/pod/Broker::Async::Worker) for more documentation about how these parameters are used.## do
my $future = $broker->do(@args);
Queue the invocation of a worker with @args.
@args can be any data structure, and is passed as is to a worker code ref.
Returns a [Future](https://metacpan.org/pod/Future) object that resolves when the work is done.There is no guarantee when a worker will be called, that depends on when a worker becomes available.
However, calls are guaranteed to be invoked in the order they are seen by $broker->do.# AUTHOR
Mark Flickinger
# LICENSE
This software is licensed under the same terms as Perl itself.