Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.8%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: cpp-for-everything
  • License: apache-2.0
  • Language: C++
  • Default Branch: main
  • Size: 314 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

📦 pubsub-lib

A lightweight, header-only C++20 Publish-Subscribe library with type-safe events, RAII-based unsubscription, and async support.


CI C++20 Header-Only License


✨ Features

  • ✅ Type-safe event publishing
  • ✅ Support for multiple publishers and event types
  • ✅ RAII-based unsubscription via SubscriptionToken
  • ✅ Subscriber lifetime management
  • ✅ Async dispatching via std::async, std::execution, or oneTBB (if found)
  • ✅ Header-only, C++20

✅ Compatibility

| OS | Compiler | Generator | Status | |----------|--------------|-------------------|--------| | Ubuntu | g++, clang++ | Makefiles, Ninja | Ubuntu | | Windows | MSVC | Visual Studio 17 | Windows | | macOS | clang++, g++ | Makefiles, Ninja | macOS |

🧪 All environments verified via GitHub Actions.


🚀 Getting Started

CMake Project Integration

bash git clone https://github.com/cpp-for-everything/pubsub-lib.git

In your CMakeLists.txt:

```cmake add_subdirectory(pubsub-lib)

targetlinklibraries(my_app PRIVATE pubsub::pubsub) ```

Or Install System-Wide

bash cmake -B build -S pubsub-lib -DCMAKE_INSTALL_PREFIX=/usr/local cmake --build build --target install

Then:

cmake find_package(pubsub REQUIRED) target_link_libraries(my_app PRIVATE pubsub::pubsub)


📃 Usage

1. Define Events

cpp constexpr auto MyEvent = pubsub::Event<void(int)>();

Or organize events:

cpp struct MyEvents { static constexpr auto Ping = pubsub::Event<void()>(); static constexpr auto Data = pubsub::Event<void(int)>(); };

2. Create a Publisher

cpp pubsub::Publisher pub;

3. Subscribe

a) Lambda or free function

cpp pub.subscribe<MyEvents::Ping>([] { std::cout << "Ping!\n"; });

b) Member function

```cpp struct Listener { void on_data(int x) { std::cout << "Got " << x << "\n"; } } obj;

pub.subscribeMyEvents::Data(&obj, &Listener::on_data); ```

c) Lifetime-aware Subscriber class

```cpp class MySubscriber : public pubsub::Subscriber { int total = 0; public: void on_data(int x) { total += x; }

void subscribe_to(pubsub::Publisher& pub) override {
    store_token(pub.subscribe<MyEvents::Data>(this, &MySubscriber::on_data));
    Subscriber::subscribe_to(pub);
}

void unsubscribe_from(pubsub::Publisher& pub) override {
    pub.unsubscribe<MyEvents::Data>(this);
}

}; ```

4. Emit Events

a) Synchronously

cpp pub.emit<MyEvents::Data>(123);

b) Using std::async

cpp pub.emit_thread_async<MyEvents::Data>(42);

c) oneTBB (if the TBB package is found by CMake)

cpp pub.emit_tbb_async<MyEvents::Data>(42);

⚠️ Make sure oneTBB is installed and discoverable by CMake.

d) Using <execution> (C++20 Parallelism TS)

cpp pub.emit_async<MyEvents::Data>(std::execution::par_unseq, 42);


🧕 Testing

bash cmake -B build -S . cmake --build build ctest --test-dir build

Includes: - Emission correctness - Lifetime management - Safe unsubscribing - Async delivery checks


📊 Benchmark

Benchmarks run using Google Benchmark with simulated heavy subscribers.

See benchmark/ for setup.

🔍 Emit Time (lower is better, log scale)

PubSub Benchmark Chart

| Strategy | 1 sub | 10 subs | 100 subs | 500 subs | 1000 subs | |----------------------------|-------|---------|----------|----------|-----------| | Sync | 1.1 µs | 10 µs | 99 µs | 534 µs | 954 µs | | std::async | 74 µs | 682 µs | 7.2 ms | 42.5 ms | 109 ms | | std::execution::seq | 1.3 µs | 12.6 µs | 130 µs | 721 µs | 1.03 ms | | std::execution::par | 1.3 µs | 14.1 µs | 186 µs | 772 µs | 1.65 ms | | std::execution::unseq | 1.6 µs | 14.4 µs | 158 µs | 803 µs | 1.50 ms | | std::execution::par_unseq | 1.5 µs | 12 µs | 149 µs | 837 µs | 1.73 ms | | oneTBB | 1.9 µs | 10.2 µs | 84 µs | 262 µs | 618 µs |

✅ Summary

  • ⚡ Use sync emit for low subscriber counts
  • ♻ Use oneTBB or par_unseq for scalable performance
  • ⛑️ Avoid std::async for high fanout

📖 Citation

If you use pubsub-lib in your research or projects, please cite the following publication:

Alex Tsvetanov and Ivan Stankov.
Modern C++ Publish/Subscribe Pattern: Design, Challenges, and Implementation.
In: Proceedings of the 60th International Scientific Conference on Information, Communication and Energy Systems and Technologies (ICEST 2025), Ohrid, North Macedonia, June 26–28, 2025.
https://github.com/cpp-for-everything/pubsub-lib


📄 License

Apache License 2.0 — see LICENSE

All source files include:

cpp // SPDX-License-Identifier: Apache-2.0


🤝 Contributing

Pull requests welcome! Please open an issue for large changes before starting work.


📬 Contact

For questions or collaborations, use GitHub Discussions.

Owner

  • Name: C++ for everything
  • Login: cpp-for-everything
  • Kind: organization

Here unified tools are being developed for the C++ geeks to be able to do anything from console to mobile applications.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software or reference its design, please cite the following publication."
title: "pubsub-lib: A Type-Safe C++ Publish-Subscribe Framework"
authors:
  - family-names: Tsvetanov
    given-names: Alex
    orcid: https://orcid.org/0009-0001-8369-150X
    affiliation: Independent Developer
  - family-names: Stankov
    given-names: Ivan
    affiliation: Technical University of Sofia
date-released: 2024-04-15
version: 1.0.0
license: Apache-2.0
repository-code: https://github.com/cpp-for-everything/pubsub-lib
url: https://github.com/cpp-for-everything/pubsub-lib
abstract: >
  pubsub-lib is a modern C++20 header-only publish-subscribe library. It provides a type-safe event system with lifetime-aware subscribers and RAII-based unsubscription. 
  The design addresses key challenges of implementing pub/sub in a statically-typed, high-performance language such as C++, while avoiding dynamic dispatch and excessive overhead.
conference:
  name: "60th International Scientific Conference on Information, Communication and Energy Systems and Technologies (ICEST)"
  location: "Ohrid, North Macedonia"
  date: "2025-06-26"
doi: 10.1109/ICEST.2025.XXXXX  # Replace this with the actual DOI once assigned

GitHub Events

Total
  • Release event: 1
  • Watch event: 1
  • Push event: 46
  • Pull request event: 6
  • Create event: 5
Last Year
  • Release event: 1
  • Watch event: 1
  • Push event: 46
  • Pull request event: 6
  • Create event: 5

Dependencies

.github/actions/setup_cache/action.yaml actions
  • actions/cache v2 composite
.github/workflows/ci.yaml actions
  • actions/checkout v4 composite