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

Evo::MDN - A message delivery network

VERSION

version 0.0159

SYNOPSIS

  use Evo::Base -strict;
  use Evo::MDN;
  my $mdn = Evo::MDN->new;

  my $sender = Evo::Base->new;
  do {
    my $foo  = Evo::Base->new;
    my $file = IO::File->new;
    $mdn->subscribe($foo,  $sender, 1, sub($me, $msg, @) { say "$me got $msg" });
    $mdn->subscribe($file, $sender, 0, sub($me, $msg, @) { say "$me got $msg" });
    $mdn->broadcast($sender, "hello");
  };

  # only Foo is alive
  $mdn->broadcast($sender, "alive");

DESCRIPTION

Message delivery network. Allows to send messages from one object to another. It do the right things in most cases.

The benefit to use it that almost any object can send and any object can receive messages without modification. So you can use your existing code or write new modules and build your app using independent components that communicate.

You can expect about 500K-1M messages/s perfomance per 1 process/processor core

METHODS

broadcast

Sends a message to all subscribers. when_message will be invoked with the sender and message for the subscribers

subscribe

Subscribe one object to another If the third passed arbument is true, stores an object and prevent it from destruction while sender exists. Default values are

  $mdn->subscribe($foo, $sender, 1, sub { shift->when_message(@_) });

But if callback is not provided, an object will be checked that method when_message exists in object's class, or an exception will be thrown

unsubscribe

Unsubscribe one object from another and deletet itself, if it was stored

unsubscribe_from_all

Unsubscribe me from all senders

AUTHOR

alexbyk.com

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by alexbyk.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.