Browse Source

skipping pushing message to client if there are no messages; fixes flaky test and de-intensifies read loop

pull/8/head
Stephen Searles 2 years ago
parent
commit
e5d16dd2d5
2 changed files with 9 additions and 3 deletions
  1. 8
    2
      deltas.go
  2. 1
    1
      doc_test.go

+ 8
- 2
deltas.go View File

@@ -92,8 +92,9 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
wroteMessagesCh := make(chan Message, 2)

client := doc.doc.Client(acedoc.DeltaHandlerFunc(func(ds []acedoc.Delta) error {
wroteMessagesCh <- Message{Deltas: ds}
return conn.WriteJSON(ch.Message(ds...))
m := ch.Message(ds...)
wroteMessagesCh <- m
return conn.WriteJSON(m)
}))

ch.mtx.Lock()
@@ -119,6 +120,11 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
}
ch.ObserveLTime(message.LTime)

if len(message.Deltas) == 0 {
time.Sleep(10 * time.Microsecond)
continue
}

err = client.PushDeltas(message.Deltas...)
if err != nil {
errCh <- err

+ 1
- 1
doc_test.go View File

@@ -233,7 +233,7 @@ func TestDeltasDouble(t *testing.T) {
// send the second message, via clientB
clientB.ReceiveJSON(w.CH.Message(acedoc.Insert(0, 0, "b")))

time.Sleep(200 * time.Millisecond)
time.Sleep(400 * time.Millisecond)

clientA.mtx.Lock()
clientB.mtx.Lock()

Loading…
Cancel
Save