mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-29 23:21:36 +00:00
39 lines
683 B
Go
39 lines
683 B
Go
|
package streams
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"sync"
|
||
|
|
||
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||
|
)
|
||
|
|
||
|
type PartitionedStreamProvider struct {
|
||
|
DB storage.Database
|
||
|
latest types.LogPosition
|
||
|
latestMutex sync.RWMutex
|
||
|
}
|
||
|
|
||
|
func (p *PartitionedStreamProvider) Setup() {
|
||
|
}
|
||
|
|
||
|
func (p *PartitionedStreamProvider) Advance(
|
||
|
latest types.LogPosition,
|
||
|
) {
|
||
|
p.latestMutex.Lock()
|
||
|
defer p.latestMutex.Unlock()
|
||
|
|
||
|
if latest.IsAfter(&p.latest) {
|
||
|
p.latest = latest
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *PartitionedStreamProvider) LatestPosition(
|
||
|
ctx context.Context,
|
||
|
) types.LogPosition {
|
||
|
p.latestMutex.RLock()
|
||
|
defer p.latestMutex.RUnlock()
|
||
|
|
||
|
return p.latest
|
||
|
}
|