]> git.giacomolli.uk - onechat/blobdiff - syncer.go
Share the Markdown marks and block parser
[onechat] / syncer.go
index 1549461a775c9863516c315d58742b4fa94f1004..3da6d7a6dec0daa7ad2d6a9ae4e004445f694e91 100644 (file)
--- a/syncer.go
+++ b/syncer.go
@@ -61,11 +61,13 @@ func (s *Syncer) Written() {
 // Flush returns when every write before the call is durable.
 func (s *Syncer) Flush(ctx context.Context) error {
        s.mutex.Lock()
+
        target := s.written
        s.mutex.Unlock()
 
        for {
                s.mutex.Lock()
+
                reached := s.durable >= target
                failure := s.failure
                done := s.done
@@ -92,6 +94,7 @@ func (s *Syncer) Flush(ctx context.Context) error {
 func (s *Syncer) Close() error {
        err := s.Flush(context.Background())
        s.workers.Wait()
+
        if s.file != nil {
                err = errors.Join(err, s.file.Close())
                s.file = nil
@@ -109,6 +112,7 @@ func (s *Syncer) start() {
 
        s.running = true
        s.workers.Add(1)
+
        go s.run(s.written)
 }
 
@@ -130,6 +134,7 @@ func (s *Syncer) run(target uint64) {
        }
 
        close(s.done)
+
        s.done = make(chan struct{})
        s.start()
 }