Description

Publish/Subscribe implementation for D

Package Information

Version~master (2014-Jan-19)
Homepage https://github.com/PaulFreund/pubsub.d
Repository https://github.com/PaulFreund/pubsub.d
LicenseBSL-1.0
AuthorsPaul Freund
Registered byPaul Freund
Dependencies none

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

pubsub.d

Publisher/Subscribe implementation for the D programming language.

Usage

To use pubsub.d just copy the code from the source directory or include it as a dependency in your dub package:

"dependencies": { 
    "pubsub-d" : "~master" 
}

Subscribing

You need to mixin the DispatchMapper before subscribers can be called:

import pubsub;
class Listeners {
    this() { mixin DispatchMapper; }
    ...
}    

After that you can subscribe to events with member functions:

@subscribe("events.importantEvent") void listenOne(string message) {
    writeln("Important event: " ~ message);
}

Insted of single events it is also possible to listen to a group of events:

@subscribe("events.*") void listenAll(string message) {
    writeln("An event has occured : " ~ message);
}


Publishing

To publish an event just call the publish function with the event name as the first parameter:

publish("events.importantEvent", "This is the important message");

Custom Dispatchers

By default pubsub uses a static dispatcher for publish and all subscribers. To create a "private" network, the DispatchMapper mixin and the publish function can be supplied with a custom Dispatcher:

class Listeners {
    this(Dispatcher _dispatcher) { mixin DispatchMapper!_dispatcher; }
    ...
}    

...
publish(_dispatcher, "eventName", "Data");





Available versions

~master