Hi,
I'm trying to implement pub/sub like communication model with the following
scheme.
*pubsub.capnp*
*interface EventPublisher{*
* interface Subscriber {*
* updateEvent @0 (event: Int32) -> ();*
* }*
* subscribe @0 (subscriber: Subscriber) -> (result: Int32);*
* unsubscribe @1 (subscriber: Subscriber) -> (result: Int32);*
*}*
I'm using *kj::Vector<EventPublisher::Subscriber::Client> m_subscribers *to
store the current subscribers.
When I try to implement unsubscribe and remove the Subscriber from the
Vector, I couldn't find good method to do that.
Could you give me some advice?
*server implementation*
*class EventPublisherImpl final : public EventPublisher::Server {*
* protected:*
* ::kj::Promise<void> subscribe(SubscribeContext context) {*
* cout << "subscribe request received" << endl;*
* m_subscribers.add(context.getParams().getSubscriber());*
* return kj::READY_NOW;*
* }*
* ::kj::Promise<void> unsubscribe(UnsubscribeContext context) {*
* cout << "unsubscribe request received" << endl;*
* auto unsub = context.getParams().getSubscriber();*
* // I want to remove usub from subscribers like
m_subscribers[unsub].erase();*
* // But I couldn't find a method to compare*
* // "EventPublisher::Subscriber::Client" such as == operator or public
method*
* // to distinguish the client.*
* //*
* // One solution is having an additional argument(id) for this purpose
but*
* // that requres additional management of ID.*
* // subscribe @0 (subscriber: Subscriber, id: Int32) -> (result:
Int32);*
* // unsubscribe @1 (id: Int32) -> (result: Int32);*
* // what I can do is erase everything but this is not my goal*
* m_subscribers.clear();*
* return kj::READY_NOW;*
* }*
* private:*
* kj::Vector<EventPublisher::Subscriber::Client> m_subscribers;*
*};*
Thank you,
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/capnproto/26c4964f-21a2-4fe2-a410-7673786d40c9n%40googlegroups.com.