mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 08:13:09 -06:00
32 lines
525 B
Go
32 lines
525 B
Go
package shared
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/matrix-org/dendrite/syncapi/types"
|
|
)
|
|
|
|
type StreamProvider struct {
|
|
DB *Database
|
|
latest types.StreamPosition
|
|
latestMutex sync.RWMutex
|
|
update *sync.Cond
|
|
}
|
|
|
|
func (p *StreamProvider) StreamSetup() {
|
|
locker := &sync.Mutex{}
|
|
p.update = sync.NewCond(locker)
|
|
}
|
|
|
|
func (p *StreamProvider) StreamAdvance(
|
|
latest types.StreamPosition,
|
|
) {
|
|
p.latestMutex.Lock()
|
|
defer p.latestMutex.Unlock()
|
|
|
|
if latest > p.latest {
|
|
p.latest = latest
|
|
p.update.Broadcast()
|
|
}
|
|
}
|