add an async subscriber impl with thread pool

This commit is contained in:
2026-01-13 03:00:32 +00:00
parent d2ef352ce9
commit 6d5e0f92ad
11 changed files with 425 additions and 0 deletions
@@ -0,0 +1,25 @@
#pragma once
#include <memory>
#include <string>
#include <unordered_map>
#include "core/subscribable.hpp"
#include "core/thread_pool.hpp"
using ProductCount = int;
using ProductId = std::string;
// inventory manager is not generic ( works with the specific types ProductId
// and ProductCount ) but the subscribable is generic
class InventoryManager : public Subscribable<ProductId, ProductCount> {
private:
std::unordered_map<ProductId, int> inventory_;
std::shared_ptr<ThreadPool> thread_pool_;
public:
explicit InventoryManager(std::shared_ptr<ThreadPool> thread_pool);
void setInventory(const ProductId& productId, ProductCount quantity);
};
@@ -0,0 +1,22 @@
#pragma once
#include "app/inventory_manager.hpp"
#include "core/subscriber.hpp"
class SmsService : public Subscriber<ProductId, ProductCount> {
public:
void onNotification(const ProductId& productId,
const ProductCount& quantity) override;
};
class EmailService : public Subscriber<ProductId, ProductCount> {
public:
void onNotification(const ProductId& productId,
const ProductCount& quantity) override;
};
class LogService : public Subscriber<ProductId, ProductCount> {
public:
void onNotification(const ProductId& productId,
const ProductCount& quantity) override;
};