MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / subscribeToPublishedEvent

Function subscribeToPublishedEvent

packages/redis/publisher.ts:45–70  ·  view source on GitHub ↗
(
  channel: Channel,
  type: keyof IPublishChannels[Channel],
  callback: (event: IPublishChannels[Channel][typeof type]) => void,
)

Source from the content-addressed store, hash-verified

43}
44
45export function subscribeToPublishedEvent<
46 Channel extends keyof IPublishChannels,
47>(
48 channel: Channel,
49 type: keyof IPublishChannels[Channel],
50 callback: (event: IPublishChannels[Channel][typeof type]) => void,
51) {
52 const subscribeChannel = getSubscribeChannel(channel, type);
53 getRedisSub().subscribe(subscribeChannel);
54
55 const message = (messageChannel: string, message: string) => {
56 if (subscribeChannel === messageChannel) {
57 const event = parsePublishedEvent(channel, type, message);
58 if (event) {
59 callback(event);
60 }
61 }
62 };
63
64 getRedisSub().on('message', message);
65
66 return () => {
67 getRedisSub().unsubscribe(subscribeChannel);
68 getRedisSub().off('message', message);
69 };
70}
71
72export function psubscribeToPublishedEvent(
73 pattern: string,

Callers 4

wsVisitorsFunction · 0.90
wsProjectEventsFunction · 0.90
wsProjectNotificationsFunction · 0.90
wsOrganizationEventsFunction · 0.90

Calls 2

getRedisSubFunction · 0.90
getSubscribeChannelFunction · 0.85

Tested by

no test coverage detected