No description, website, or topics provided.
Perl6
Latest commit b74c881 Dec 21, 2016 tony-o version update
Permalink
Failed to load latest commit information.
lib/Event role template Dec 21, 2016
t role template Dec 21, 2016
.gitignore travis + gitignore May 5, 2016
.travis.yml travis + gitignore May 5, 2016
META.info readme updated and META created Apr 10, 2015
META6.json version update Dec 21, 2016
README.md Mention unit declarator in README docs May 24, 2015

README.md

#Event::Emitter

An extendable JS like event emitter but way more fun. Can use supplies or channels and is basically just some syntax sugar on already implemented Perl6 features.

##Syntax

Out of the box functionality

###Single thread

Event::Emitter uses a Supply in the back end

use Event::Emitter;

my Event::Emitter $e .= new;

#hey, i work with regex
$e.on(/^^ "Some regex"/, -> $data {
  qw<do something with your $data here>;
});

#your own callables to match events
my $event = { 'some flag' => 3, 'some other flag' => 5 };
$e.on({ $event<some flag> // Nil eq $*STATE }, -> $data {
  qw<do something with your $data here>;
});

#plain ol strings, just like mom used to make
$e.on('some str', -> $data {
  qw<do something with your $data here>;
});

#runs the some str listener
$e.emit('some str', @(1 .. 5)); 

#runs the regex because it matches the regex;
$e.emit('Some regex', { conn => IO::Socket::INET }); 

$e.emit({ 'some flag' => 5 }, { });

###Thread

Event::Emitter uses a Channel in the back end

use Event::Emitter;

my Event::Emitter $e .= new(:threaded);

##Rolling your own Event::Emitter

Want to make your own receiver/emitter? Here's a template

###Your new .pm6 file

use Event::Emitter::Role::Handler;

unit class My::Own::Emitter does Event::Emitter::Role::Handler;

method on($event, $data) {
  qw<do your thing>;
}

method emit($event, $data?) {
  qw<do your thing here>;
}

###Later in your .pl6

use Event::Emitter;


my $e = Event::Emitter.new(:class<My::Own::Emitter>);

#License

Free for all.