From 3a52f7dbebb21ab4dec9f7855279fe3ca8a095c8 Mon Sep 17 00:00:00 2001 From: AdaAibaby Date: Fri, 29 May 2026 14:16:41 +0800 Subject: [PATCH] Optimize the comment of Notifier.Subscribe method --- .../sandbox/storage/redis/notifier.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/api/internal/sandbox/storage/redis/notifier.go diff --git a/packages/api/internal/sandbox/storage/redis/notifier.go b/packages/api/internal/sandbox/storage/redis/notifier.go new file mode 100644 index 0000000000..3053d3d6b7 --- /dev/null +++ b/packages/api/internal/sandbox/storage/redis/notifier.go @@ -0,0 +1,30 @@ +package redis + +import ( + "context" +) + +// Notifier is the public seam onto the shared storage pub/sub infrastructure. +type Notifier struct { + sub *subscriptionManager + pub *publisher +} + +// Subscribe registers interest in routingKey. The returned channel is +// signaled (non-blocking, drop-on-full) whenever a matching message +// arrives on the shared notify channel. The caller MUST invoke the +// returned cleanup function when done to avoid a memory leak. +func (n *Notifier) Subscribe(routingKey string) (<-chan struct{}, func()) { + return n.sub.subscribe(routingKey) +} + +// Publish enqueues routingKey for asynchronous PUBLISH on the shared +// notify channel. Every consumer should use a fallback ticker. +func (n *Notifier) Publish(ctx context.Context, routingKey string) { + n.pub.Publish(ctx, routingKey) +} + +// Notifier returns the cross-package pub/sub seam +func (s *Storage) Notifier() *Notifier { + return &Notifier{sub: s.subManager, pub: s.publisher} +}