The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

ZMQ::Raw::Loop::Promise - Promise class

VERSION

version 0.16

DESCRIPTION

A ZMQ::Raw::Loop::Promise represents a promise

WARNING: The API of this module is unstable and may change without warning (any change will be appropriately documented in the changelog).

SYNOPSIS

use ZMQ::Raw;

my $context = ZMQ::Raw::Context->new;
my $loop = ZMQ::Raw::Loop->new ($context);

my $promise = ZMQ::Raw::Loop::Promise->new ($loop);
$promise->then (sub
	{
		my $promise = shift;
		print "Promise kept/broken: ", $promise->result, "\n";
	}
);

my $timer = ZMQ::Raw::Loop::Timer->new (
	timer => ZMQ::Raw::Timer->new ($context, after => 100),
	on_timeout => sub
	{
		$promise->keep ('done');
	}
);

$loop->add ($timer);
$loop->run();

METHODS

new( $loop )

Create a new promise.

status( )

Get the status of the promise. One of PLANNED, KEPT or BROKEN.

await( )

Wait for the promise to be kept or broken.

result( )

Wait for the promise to be kept or broken, if its kept the result will be returned, otherwise throws the cause.

cause( )

Get the reason why the promise was broken. This method will croak if the promise is still planned or has been kept.

break( $result )

Break the promise, setting the cause to $result.

keep( $result )

Keep the promise, setting its result to $result.

then( \&callback )

Schedule \&callback to be fired when the promise is either kept or broken. Returns a new ZMQ::Raw::Loop::Promise.

CONSTANTS

PLANNED

The promise is still planned.

KEPT

The promise has been kept.

BROKEN

The promise was broken.

AUTHOR

Jacques Germishuys <jacquesg@striata.com>

LICENSE AND COPYRIGHT

Copyright 2017 Jacques Germishuys.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.