seb 0.3.1

Simple event bus — The simple thread-safety multithreaded event system

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:

Simple event bus — Thread-Safe Multithreaded Event System

This repository contains a simple implementation of a thread-safe, multithreaded event system in the D programming language.


The event system consists of an SEBSingleton class that manages event publication and subscription. The event bus can have multiple subscribers that listen for events. When an event is published, all subscribers will receive the event and can react accordingly.

The event bus uses D's std.parallelism library to handle events in parallel across multiple threads, ensuring efficient utilization of system resources.

Please note that the library does not provide a subscription to an event not from the main thread. Perhaps we will do this in the future.


Subscribing to Events

Subscribers can register a delegate function that will be called whenever an event of a particular type is posted:

// register a handler function for the TestEvent
EventBus.subscribe!TestEvent((event) {
	writeln("Test event has occurred");

Publishing Events

Event can be published to the bus by calling the publish function:

EventBus.publish(new TestEvent);

Starting and Stopping Event Dispatching

To start dispatching events, call the startDispatching method:


To stop dispatching events, call the stopDispatching method:


Event cancellation

EventBus.subscribe!KeyPressEvent((event) {
	if(event.keyCode == 42) {

After the event is cancelled, it is lazily removed from the queue.


Here is a complete example of using the event system:

import seb;
import std.stdio;

class TestEvent : Event {}

class KeyPressEvent : Event
    int keyCode;
    this(int code)
        keyCode = code;

void main()
    // Register event handlers
    EventBus.subscribe!TestEvent((event) {
        writeln("Test event has occurred");
    EventBus.subscribe!KeyPressEvent((event) {
        writeln("Key with code ", event.keyCode, " has been pressed!");

    // Start dispatching events

    // Publish events
    EventBus.publish(new TestEvent);
    EventBus.publish(new KeyPressEvent(42));

    scope (exit)

This will print:

Test event has occurred
Key with code 42 has been pressed!


  • [X] Cancelable events
  • [ ] Rewrite to actor model
  • [ ] Subscriber priority
  • [ ] Unsubscribe
  • [ ] Middleware
  • [ ] Subscribe to an event from another thread
  • [ ] Unittests
  • Bagomot
0.3.1 2023-Aug-17
0.3.0 2023-Aug-15
0.2.1 2023-Aug-14
0.2.0 2023-Aug-14
~main 2023-Aug-17
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 16 downloads total

Short URL: