pubsub-d ~master
Publish/Subscribe implementation for D
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
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");
- Registered by Paul Freund
- ~master released 10 years ago
- PaulFreund/pubsub.d
- github.com/PaulFreund/pubsub.d
- BSL-1.0
- Authors:
- Dependencies:
- none
- Versions:
-
~master 2014-Jan-19 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
198 downloads total
-
- Score:
- 1.3
- Short URL:
- pubsub-d.dub.pm