diff options
author | 2024-05-27 09:35:41 +0000 | |
---|---|---|
committer | 2024-05-27 09:35:41 +0000 | |
commit | 0a18c0d802ce76cac5eb4cf2dae53c6e42536601 (patch) | |
tree | 8d28ddc527edcb323cbdba9330e7b705bdcf6c59 /vendor/github.com/jackc/pgx/v5/pgconn/internal | |
parent | [performance] update storage backend and make use of seek syscall when availa... (diff) | |
download | gotosocial-0a18c0d802ce76cac5eb4cf2dae53c6e42536601.tar.xz |
[chore]: Bump github.com/jackc/pgx/v5 from 5.5.5 to 5.6.0 (#2929)
Diffstat (limited to 'vendor/github.com/jackc/pgx/v5/pgconn/internal')
-rw-r--r-- | vendor/github.com/jackc/pgx/v5/pgconn/internal/ctxwatch/context_watcher.go | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/vendor/github.com/jackc/pgx/v5/pgconn/internal/ctxwatch/context_watcher.go b/vendor/github.com/jackc/pgx/v5/pgconn/internal/ctxwatch/context_watcher.go deleted file mode 100644 index b39cb3ee5..000000000 --- a/vendor/github.com/jackc/pgx/v5/pgconn/internal/ctxwatch/context_watcher.go +++ /dev/null @@ -1,73 +0,0 @@ -package ctxwatch - -import ( - "context" - "sync" -) - -// ContextWatcher watches a context and performs an action when the context is canceled. It can watch one context at a -// time. -type ContextWatcher struct { - onCancel func() - onUnwatchAfterCancel func() - unwatchChan chan struct{} - - lock sync.Mutex - watchInProgress bool - onCancelWasCalled bool -} - -// NewContextWatcher returns a ContextWatcher. onCancel will be called when a watched context is canceled. -// OnUnwatchAfterCancel will be called when Unwatch is called and the watched context had already been canceled and -// onCancel called. -func NewContextWatcher(onCancel func(), onUnwatchAfterCancel func()) *ContextWatcher { - cw := &ContextWatcher{ - onCancel: onCancel, - onUnwatchAfterCancel: onUnwatchAfterCancel, - unwatchChan: make(chan struct{}), - } - - return cw -} - -// Watch starts watching ctx. If ctx is canceled then the onCancel function passed to NewContextWatcher will be called. -func (cw *ContextWatcher) Watch(ctx context.Context) { - cw.lock.Lock() - defer cw.lock.Unlock() - - if cw.watchInProgress { - panic("Watch already in progress") - } - - cw.onCancelWasCalled = false - - if ctx.Done() != nil { - cw.watchInProgress = true - go func() { - select { - case <-ctx.Done(): - cw.onCancel() - cw.onCancelWasCalled = true - <-cw.unwatchChan - case <-cw.unwatchChan: - } - }() - } else { - cw.watchInProgress = false - } -} - -// Unwatch stops watching the previously watched context. If the onCancel function passed to NewContextWatcher was -// called then onUnwatchAfterCancel will also be called. -func (cw *ContextWatcher) Unwatch() { - cw.lock.Lock() - defer cw.lock.Unlock() - - if cw.watchInProgress { - cw.unwatchChan <- struct{}{} - if cw.onCancelWasCalled { - cw.onUnwatchAfterCancel() - } - cw.watchInProgress = false - } -} |