Help language development. Donate to The Perl Foundation

EventSource::Server zef:jonathanstowe last updated on 2022-08-07



A simple handler to provide Server Sent Events from Raku applications

Build Status


This sends out an event with the DateTime string every second

use EventSource::Server;
use HTTP::Server::Tiny;

my $supply = Supply.interval(1).map( { => 'tick', data => } );

my &es =$supply); => 7798).run(&es)

Or using Cro:

use EventSource::Server;

use Cro::HTTP::Router;
use Cro::HTTP::Server;

my $supply = Supply.interval(1).map( { => 'tick', data => } );

my $es =$supply);

my $app = route {
    get -> {
        content 'text/event-stream', $es.out-supply;

my Cro::Service $tick =<localhost>, :port<7798>, application => $app);


react whenever signal(SIGINT) { $tick.stop; exit; }

And in some Javascript program somewhere else:

var EventSource = require('eventsource');

var v = new EventSource('');

v.addEventListener("tick", function(e) {;

}, false);

See also the examples directory in this distribution.


This provides a simple mechanism for creating a source of Server Sent Events in a web server application.

The EventSource interface is implemented by most modern web browsers and provides a lightweight alternative to Websockets for those applications where only a uni-directional message is required (for example for notifications,)


Assuming you have a working installation of Rakudo with zef installed then you should be able to install this with:

zef install EventSource::Server

If you want to install this from a local copy substitute the distribution name for the path to the local copy.


This is quite a simple module but is fairly difficult to test well without bringing in a vast array of large and otherwise un-needed modules, so I won't be surprised there are bugs, similarly whilst I have tested for interoperability with the Javascript hosts that I have available to me I haven't tested against every known host that provides the EventSource interface.

So please feel free to report any problems (or make suggestions,) to

This is free software, please see the LICENCE file in the distribution.

© Jonathan Stowe 2017 - 2021