account page: fixed platform reordering bugs
This commit is contained in:
@@ -2,9 +2,11 @@ package sse
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -120,6 +122,34 @@ func (p *UpdateNotificationPublisher) Publish(pathPattern string) gin.HandlerFun
|
||||
}
|
||||
}
|
||||
|
||||
func (p *UpdateNotificationPublisher) Push(ctx context.Context, acctID int64, eventTypes ...string) error {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(eventTypes))
|
||||
|
||||
errs := make([]error, len(eventTypes))
|
||||
for i, e := range eventTypes {
|
||||
i := i
|
||||
e := e
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := p.queue.Send(ctx, Event{
|
||||
AccountID: acctID,
|
||||
Type: e,
|
||||
Data: []byte(fmt.Sprintf(`{"eventType": %q}`, e)),
|
||||
}); err != nil {
|
||||
errs[i] = fmt.Errorf("failed to send sse event to listener: %w", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return errors.Join(errs...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPathSegments(p string) []string {
|
||||
p = path.Clean(p)
|
||||
if p == "" || p == "." || p == "/" {
|
||||
|
||||
Reference in New Issue
Block a user