#1 2020-12-30 14:40:37

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Events without subscribe

[Websockets] I would like to send all authenticated users a lot of different events. Can I do it without defining callback interface in any dedicated method parameter?

Based on Project31ChatServer.dpr, can I send the NotifyBlaBla without subscribing to any event by Join( ) method.

If it is not possible what is the right solution for subscribing to "all" events? Below is one of my ideas

type
  IEvent1 = interface
    procedure Event1(const parameter: string)
  end

  IEvent2 = interface
    procedure Event2(const parameter: string; const Param2: array)
  end

IEvents = interface()
public
  procedure Subscribe(const callback: IEvent1);
  procedure Subscribe(const callback: IEvent2);
  ...
  procedure Subscribe(const callback: IEvent100);

Offline

#2 2020-12-30 16:33:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Events without subscribe

Don't create one interface per event, but one method per event.

Then use an enumerate to identify the events, and make the subscription using a set of this enumeration.

Offline

#3 2020-12-30 19:45:20

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Re: Events without subscribe

So, you meant:

type
  ICallbacks = interface
    procedure Event1(const parameter: string);
    procedure Event2(const parameter: string; const Param2: array);
     ....
    procedure Event100(const parameter: string; const Param222: array);
  end

IEvents = interface()
public
  procedure Subscribe(const callback: ICallbacks);

Offline

#4 2020-12-31 09:29:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Events without subscribe

More like:

type
  TMyEvent = (eEvent1, eEvent2, ... eEvent100);
  TMyEvents = set of TMyEvent;

IEvents = interface()
   procedure Subscribe(events: TMyEvents; const callback: ICallbacks);

Offline

Board footer

Powered by FluxBB