commit 6168b6f948bc55ecd6bded17afa41d9a4dd73125
parent 5d39d5207b44bb4d0d241530a3e47e16ff6f52a3
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 24 May 2023 07:21:26 -0700
simplify code
Diffstat:
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -2,6 +2,7 @@ package handlers
import (
"bytes"
+ "context"
cryptoRand "crypto/rand"
"crypto/sha256"
dutils "dkforest/pkg/database/utils"
@@ -4928,19 +4929,16 @@ func (m *UsersStreamsManager) Remove(userID database.UserID) {
var usersStreamsManager = NewUsersStreamsManager()
func closeSignalChan(c echo.Context) <-chan struct{} {
- out := make(chan struct{})
- quit := make(chan struct{})
- quit1 := make(chan struct{})
+ ctx, cancel := context.WithCancel(context.Background())
// Listen to the closing of HTTP connection via CloseNotifier
notify := c.Request().Context().Done()
utils.SGo(func() {
select {
case <-notify:
- close(out)
- case <-quit1:
+ case <-ctx.Done():
}
- close(quit)
+ cancel()
})
notify1 := make(chan os.Signal)
@@ -4948,13 +4946,12 @@ func closeSignalChan(c echo.Context) <-chan struct{} {
utils.SGo(func() {
select {
case <-notify1:
- close(out)
- case <-quit:
+ case <-ctx.Done():
}
- close(quit1)
+ cancel()
})
- return out
+ return ctx.Done()
}
func ChatStreamMessagesHandler(c echo.Context) error {