mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-21 04:57:18 +02:00
pkg/storage: make Watch returns receive only channel (#1211)
So the caller can not write to the channel, and insist that the channel is for notifying only.
This commit is contained in:
parent
f4cb5ea6e9
commit
ec52412d79
4 changed files with 5 additions and 5 deletions
|
@ -137,7 +137,7 @@ func (db *DB) Put(_ context.Context, id string, data *anypb.Any) error {
|
||||||
|
|
||||||
// Watch returns the underlying signal.Signal binding channel to the caller.
|
// Watch returns the underlying signal.Signal binding channel to the caller.
|
||||||
// Then the caller can listen to the channel for detecting changes.
|
// Then the caller can listen to the channel for detecting changes.
|
||||||
func (db *DB) Watch(ctx context.Context) chan struct{} {
|
func (db *DB) Watch(ctx context.Context) <-chan struct{} {
|
||||||
ch := db.onchange.Bind()
|
ch := db.onchange.Bind()
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|
|
@ -324,7 +324,7 @@ func (db *DB) subscribeRedisChannel(psc *redis.PubSubConn) error {
|
||||||
|
|
||||||
// Watch returns a channel to the caller, when there is a change to the version set,
|
// Watch returns a channel to the caller, when there is a change to the version set,
|
||||||
// sending message to the channel to notify the caller.
|
// sending message to the channel to notify the caller.
|
||||||
func (db *DB) Watch(ctx context.Context) chan struct{} {
|
func (db *DB) Watch(ctx context.Context) <-chan struct{} {
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
c := db.pool.Get()
|
c := db.pool.Get()
|
||||||
|
|
|
@ -33,5 +33,5 @@ type Backend interface {
|
||||||
// Watch returns a channel to the caller. The channel is used to notify
|
// Watch returns a channel to the caller. The channel is used to notify
|
||||||
// about changes that happen in storage. When ctx is finished, Watch will close
|
// about changes that happen in storage. When ctx is finished, Watch will close
|
||||||
// the channel.
|
// the channel.
|
||||||
Watch(ctx context.Context) chan struct{}
|
Watch(ctx context.Context) <-chan struct{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ type mockBackend struct {
|
||||||
list func(ctx context.Context, sinceVersion string) ([]*databroker.Record, error)
|
list func(ctx context.Context, sinceVersion string) ([]*databroker.Record, error)
|
||||||
delete func(ctx context.Context, id string) error
|
delete func(ctx context.Context, id string) error
|
||||||
clearDeleted func(ctx context.Context, cutoff time.Time)
|
clearDeleted func(ctx context.Context, cutoff time.Time)
|
||||||
watch func(ctx context.Context) chan struct{}
|
watch func(ctx context.Context) <-chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockBackend) Put(ctx context.Context, id string, data *anypb.Any) error {
|
func (m *mockBackend) Put(ctx context.Context, id string, data *anypb.Any) error {
|
||||||
|
@ -42,6 +42,6 @@ func (m *mockBackend) ClearDeleted(ctx context.Context, cutoff time.Time) {
|
||||||
m.clearDeleted(ctx, cutoff)
|
m.clearDeleted(ctx, cutoff)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockBackend) Watch(ctx context.Context) chan struct{} {
|
func (m *mockBackend) Watch(ctx context.Context) <-chan struct{} {
|
||||||
return m.watch(ctx)
|
return m.watch(ctx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue