#!/usr/bin/env perl

use strict;
use warnings;

use Zing::Zang;

=pod explain

- see ./examples/00-zing-zang

- zing-zang is simple a Zing/Process
- it provides on_perform() and on_receive() handlers
- the defer() method allows a process to send a message to itself ...
- which is a useful mechanism for creating task lists and chunking work

- in this example the process ...
- 1) calls perform which puts a message in its own mailbox
- 2) calls receive because the mailbox has a message which prints the time

=cut

my $z = Zing::Zang->new(
  on_perform => sub {
    my ($self) = @_;

    $self->defer({ time => time });

    return;
  },
  on_receive => sub {
    my ($self, $from, $data) = @_;

    # from myself
    return unless $self->term eq $from;

    warn $from, ' ', $data->{time};

    return;
  }
);

$z->exercise;
