mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
use cancel cause
This commit is contained in:
parent
23366129fa
commit
d1350f0447
1 changed files with 4 additions and 3 deletions
|
@ -2,6 +2,7 @@ package events
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -47,7 +48,7 @@ type (
|
||||||
type Target[T any] struct {
|
type Target[T any] struct {
|
||||||
initOnce sync.Once
|
initOnce sync.Once
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelCauseFunc
|
||||||
addListenerCh chan addListenerEvent[T]
|
addListenerCh chan addListenerEvent[T]
|
||||||
removeListenerCh chan removeListenerEvent[T]
|
removeListenerCh chan removeListenerEvent[T]
|
||||||
dispatchCh chan dispatchEvent[T]
|
dispatchCh chan dispatchEvent[T]
|
||||||
|
@ -74,7 +75,7 @@ func (t *Target[T]) AddListener(listener Listener[T]) Handle {
|
||||||
func (t *Target[T]) Close() {
|
func (t *Target[T]) Close() {
|
||||||
t.init()
|
t.init()
|
||||||
|
|
||||||
t.cancel()
|
t.cancel(errors.New("target closed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch dispatches an event to any listeners.
|
// Dispatch dispatches an event to any listeners.
|
||||||
|
@ -99,7 +100,7 @@ func (t *Target[T]) RemoveListener(handle Handle) {
|
||||||
|
|
||||||
func (t *Target[T]) init() {
|
func (t *Target[T]) init() {
|
||||||
t.initOnce.Do(func() {
|
t.initOnce.Do(func() {
|
||||||
t.ctx, t.cancel = context.WithCancel(context.Background())
|
t.ctx, t.cancel = context.WithCancelCause(context.Background())
|
||||||
t.addListenerCh = make(chan addListenerEvent[T], 1)
|
t.addListenerCh = make(chan addListenerEvent[T], 1)
|
||||||
t.removeListenerCh = make(chan removeListenerEvent[T], 1)
|
t.removeListenerCh = make(chan removeListenerEvent[T], 1)
|
||||||
t.dispatchCh = make(chan dispatchEvent[T], 1)
|
t.dispatchCh = make(chan dispatchEvent[T], 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue