Invalidate UI on approval queue changes

This commit is contained in:
Joe Julian
2026-04-11 09:53:23 -07:00
parent 2ef571c241
commit 852c115b2a
3 changed files with 50 additions and 0 deletions
+18
View File
@@ -50,6 +50,7 @@ type Broker struct {
timeout time.Duration
now func() time.Time
nextID func() string
notify func()
}
type pendingRequest struct {
@@ -108,6 +109,15 @@ func (b *Broker) Pending() []Request {
return requests
}
func (b *Broker) SetChangeNotifier(notify func()) {
if b == nil {
return
}
b.mu.Lock()
defer b.mu.Unlock()
b.notify = notify
}
func (b *Broker) Request(ctx context.Context, token apitokens.Token, op apitokens.Operation, resource apitokens.Resource) (Result, error) {
if b == nil {
return Result{}, ErrRequestTimedOut
@@ -128,12 +138,20 @@ func (b *Broker) Request(ctx context.Context, token apitokens.Token, op apitoken
b.mu.Lock()
b.pending[pending.request.ID] = pending
notify := b.notify
b.mu.Unlock()
if notify != nil {
notify()
}
defer func() {
b.mu.Lock()
delete(b.pending, pending.request.ID)
notify := b.notify
b.mu.Unlock()
if notify != nil {
notify()
}
}()
timer := time.NewTimer(b.timeout)