mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Pulls in upstream latest changes from [dendrite-fork ](https://github.com/HereNotThere/dendrite)to subtree at servers/dendrite here. Co-authored-by: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com> Co-authored-by: Tak Wai Wong <tak@hntlabs.com> Co-authored-by: John Terzis <john@hntlabs.com>
41 lines
729 B
Go
41 lines
729 B
Go
package streams
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
|
"github.com/matrix-org/dendrite/syncapi/types"
|
|
)
|
|
|
|
type DefaultStreamProvider struct {
|
|
DB storage.Database
|
|
latest types.StreamPosition
|
|
latestMutex sync.RWMutex
|
|
}
|
|
|
|
func (p *DefaultStreamProvider) Setup(
|
|
ctx context.Context, snapshot storage.DatabaseTransaction,
|
|
) {
|
|
}
|
|
|
|
func (p *DefaultStreamProvider) Advance(
|
|
latest types.StreamPosition,
|
|
) {
|
|
p.latestMutex.Lock()
|
|
defer p.latestMutex.Unlock()
|
|
|
|
if latest > p.latest {
|
|
p.latest = latest
|
|
}
|
|
}
|
|
|
|
func (p *DefaultStreamProvider) LatestPosition(
|
|
ctx context.Context,
|
|
) types.StreamPosition {
|
|
p.latestMutex.RLock()
|
|
defer p.latestMutex.RUnlock()
|
|
|
|
return p.latest
|
|
}
|