Skip to content

Commit 3c23640

Browse files
authored
Merge branch 'development' into grpc-improvement
2 parents 189631e + 56da741 commit 3c23640

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/gofr/subscriber.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gofr
33
import (
44
"context"
55
"runtime/debug"
6+
"time"
67

78
"gofr.dev/pkg/gofr/container"
89
"gofr.dev/pkg/gofr/logging"
@@ -24,15 +25,19 @@ func newSubscriptionManager(c *container.Container) SubscriptionManager {
2425

2526
// startSubscriber continuously subscribes to a topic and handles messages using the provided handler.
2627
func (s *SubscriptionManager) startSubscriber(ctx context.Context, topic string, handler SubscribeFunc) error {
28+
var delay time.Duration
29+
2730
for {
2831
select {
2932
case <-ctx.Done():
3033
s.container.Logger.Infof("shutting down subscriber for topic %s", topic)
3134
return nil
32-
default:
35+
case <-time.After(delay):
3336
err := s.handleSubscription(ctx, topic, handler)
3437
if err != nil {
3538
s.container.Logger.Errorf("error in subscription for topic %s: %v", topic, err)
39+
40+
delay = time.Second * 2
3641
}
3742
}
3843
}

0 commit comments

Comments
 (0)