NAME

Zing::Loop - Event Loop

ABSTRACT

Process Event Loop

SYNOPSIS

use Zing::Flow;
use Zing::Loop;

my $loop = Zing::Loop->new(
  flow => Zing::Flow->new(name => 'init', code => sub {1})
);

DESCRIPTION

This package provides represents the process event-loop, it is implemented as an infinite loop which executes Zing::Flow objects.

LIBRARIES

This package uses type constraints from:

Zing::Types

ATTRIBUTES

This package has the following attributes:

flow

flow(Flow)

This attribute is read-only, accepts (Flow) values, and is required.

last

last(Bool)

This attribute is read-only, accepts (Bool) values, and is optional.

stop

stop(Bool)

This attribute is read-only, accepts (Bool) values, and is optional.

METHODS

This package implements the following methods:

execute

execute(Any @args) : Object

The execute method executes the event-loop indefinitely.

execute example #1
# given: synopsis

$loop->execute;

exercise

exercise(Any @args) : Object

The exercise method executes the event-loop and stops after the first cycle.

exercise example #1
# given: synopsis

$loop->exercise;
exercise example #2
package Loop;

our $i = 0;

my $flow_0 = Zing::Flow->new(
  name => 'flow_0',
  code => sub {
    my ($flow, $loop) = @_; $loop->stop(1);
  }
);
my $flow_1 = $flow_0->next(Zing::Flow->new(
  name => 'flow_1',
  code => sub {
    my ($flow, $loop) = @_; $i++;
  }
));

my $loop = Zing::Loop->new(flow => $flow_0);

$loop->exercise;
exercise example #3
package Loop;

our $i = 0;

my $flow_0 = Zing::Flow->new(
  name => 'flow_0',
  code => sub {
    my ($flow, $loop) = @_; $loop->last(1);
  }
);
my $flow_1 = $flow_0->next(Zing::Flow->new(
  name => 'flow_1',
  code => sub {
    my ($flow, $loop) = @_; $i++;
  }
));

my $loop = Zing::Loop->new(flow => $flow_0);

$loop->exercise;

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues