Invalidate UI on approval queue changes
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user