diff options
| author | 2023-07-21 14:22:20 +0000 | |
|---|---|---|
| committer | 2023-07-21 14:22:20 +0000 | |
| commit | fa57c699fe9d2db81d7806d6e30c0e388fa01673 (patch) | |
| tree | dd0f2d52be007f8207d3ff4b851d13e46ec26625 /vendor/github.com/jackc/pgx/v5/pgconn/internal | |
| parent | [chore]: Bump github.com/minio/minio-go/v7 from 7.0.59 to 7.0.60 (#1992) (diff) | |
| download | gotosocial-fa57c699fe9d2db81d7806d6e30c0e388fa01673.tar.xz | |
[chore]: Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#1991)
Diffstat (limited to 'vendor/github.com/jackc/pgx/v5/pgconn/internal')
| -rw-r--r-- | vendor/github.com/jackc/pgx/v5/pgconn/internal/bgreader/bgreader.go | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/vendor/github.com/jackc/pgx/v5/pgconn/internal/bgreader/bgreader.go b/vendor/github.com/jackc/pgx/v5/pgconn/internal/bgreader/bgreader.go index aa1a3d39c..e65c2c2bf 100644 --- a/vendor/github.com/jackc/pgx/v5/pgconn/internal/bgreader/bgreader.go +++ b/vendor/github.com/jackc/pgx/v5/pgconn/internal/bgreader/bgreader.go @@ -9,18 +9,18 @@ import ( ) const ( - bgReaderStatusStopped = iota - bgReaderStatusRunning - bgReaderStatusStopping + StatusStopped = iota + StatusRunning + StatusStopping ) // BGReader is an io.Reader that can optionally buffer reads in the background. It is safe for concurrent use. type BGReader struct { r io.Reader - cond *sync.Cond - bgReaderStatus int32 - readResults []readResult + cond *sync.Cond + status int32 + readResults []readResult } type readResult struct { @@ -34,14 +34,14 @@ func (r *BGReader) Start() { r.cond.L.Lock() defer r.cond.L.Unlock() - switch r.bgReaderStatus { - case bgReaderStatusStopped: - r.bgReaderStatus = bgReaderStatusRunning + switch r.status { + case StatusStopped: + r.status = StatusRunning go r.bgRead() - case bgReaderStatusRunning: + case StatusRunning: // no-op - case bgReaderStatusStopping: - r.bgReaderStatus = bgReaderStatusRunning + case StatusStopping: + r.status = StatusRunning } } @@ -51,16 +51,23 @@ func (r *BGReader) Stop() { r.cond.L.Lock() defer r.cond.L.Unlock() - switch r.bgReaderStatus { - case bgReaderStatusStopped: + switch r.status { + case StatusStopped: // no-op - case bgReaderStatusRunning: - r.bgReaderStatus = bgReaderStatusStopping - case bgReaderStatusStopping: + case StatusRunning: + r.status = StatusStopping + case StatusStopping: // no-op } } +// Status returns the current status of the background reader. +func (r *BGReader) Status() int32 { + r.cond.L.Lock() + defer r.cond.L.Unlock() + return r.status +} + func (r *BGReader) bgRead() { keepReading := true for keepReading { @@ -70,8 +77,8 @@ func (r *BGReader) bgRead() { r.cond.L.Lock() r.readResults = append(r.readResults, readResult{buf: buf, err: err}) - if r.bgReaderStatus == bgReaderStatusStopping || err != nil { - r.bgReaderStatus = bgReaderStatusStopped + if r.status == StatusStopping || err != nil { + r.status = StatusStopped keepReading = false } r.cond.L.Unlock() @@ -89,7 +96,7 @@ func (r *BGReader) Read(p []byte) (int, error) { } // There are no unread background read results and the background reader is stopped. - if r.bgReaderStatus == bgReaderStatusStopped { + if r.status == StatusStopped { return r.r.Read(p) } |
