Manifesto

NAME

Manifesto - Make a supply of the results of Promises

SYNOPSIS

Yet another version of the "sleep sort"


use Manifesto;

my $manifesto = Manifesto.new;

for (^10).pick(*).map( -> $i { Promise.in($i + 0.5).then({ $i })}) -> $p {
    $manifesto.add-promise($p);
}

my $channel = Channel.new;

react {
    whenever $manifesto -> $v {
        $channel.send: $v;
    }
    whenever $manifesto.empty {
        $channel.close;
        done;
    }
}

say $channel.list;

DESCRIPTION

This manages a collection of Promise objects and provides a Supply of the result of the kept Promises.

This is useful to aggregate a number of Promises to a single stream of results, which may then be used in, a react or supply block or othewise tapped.

METHODS

method new

method new() returns Manifesto

The constructor takes no arguments.

method Supply

method Supply() returns Supply

This returns the Supply on which will be emited the results of the kept managed Promises, (it is named Supply so the Manifesto object can be 'coerced' into a Supply in for instance a whenever.

method add-promise

method add-promise(Promise $promise) returns Bool

This adds a Promise to be managed by this object, it will return True if the Promise was successfully added, it will not be added if it is not in state Planned.

method empty

method empty() returns Supply

This returns a Supply which will emit an event (with the value of True,) whenever the list of Planned Promises is exhausted.

method exception

method exception() returns Supply

This returns a Supply onto which the exceptions from broken Promises are emitted.

method promises

method promises() returns Array[Promise]

This is a list of the Promises that are yet to be kept, when they are kept (or broken,) then they will be removed.

Manifesto v0.0.6

Make a supply of the results of Promises

Authors

  • Jonathan Stowe

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Manifesto

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.