Skip to content

Commit

Permalink
Update subsciptions documentation to correctly close channel (#2753)
Browse files Browse the repository at this point in the history
  • Loading branch information
leangaurav authored Aug 9, 2023
1 parent 2d8673a commit d6270e4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/content/recipes/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func (r *subscriptionResolver) CurrentTime(ctx context.Context) (<-chan *model.T
// You can (and probably should) handle your channels in a central place outside of `schema.resolvers.go`.
// For this example we'll simply use a Goroutine with a simple loop.
go func() {
// Handle deregistration of the channel here. Note the `defer`
defer close(ch)

for {
// In our example we'll send the current time every second.
time.Sleep(1 * time.Second)
Expand Down Expand Up @@ -294,6 +297,8 @@ func (r *subscriptionResolver) CurrentTime(ctx context.Context) (<-chan *model.T
ch := make(chan *model.Time)

go func() {
defer close(ch)

for {
time.Sleep(1 * time.Second)
fmt.Println("Tick")
Expand Down

0 comments on commit d6270e4

Please # to comment.