use chatwait for streaming instead of statewait polling
This commit is contained in:
parent
f4e844b0a6
commit
b46f2c92b8
|
|
@ -0,0 +1 @@
|
||||||
|
ollie-acme
|
||||||
27
main.go
27
main.go
|
|
@ -203,38 +203,27 @@ func (cw *chatWin) eventLoop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tail polls the chat file and appends new content to the window.
|
// tail reads chatwait in a loop to stream new content to the window.
|
||||||
func (cw *chatWin) tail() {
|
func (cw *chatWin) tail() {
|
||||||
chatPath := filepath.Join(ollie, "s", cw.sid, "chat")
|
cwPath := filepath.Join(ollie, "s", cw.sid, "chatwait")
|
||||||
swPath := filepath.Join(ollie, "s", cw.sid, "statewait")
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// statewait blocks until a state transition.
|
data, err := os.ReadFile(cwPath)
|
||||||
_, err := os.ReadFile(swPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Session gone — stop tailing.
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cw.flush(chatPath)
|
if len(data) > 0 {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cw *chatWin) flush(chatPath string) {
|
|
||||||
data, err := os.ReadFile(chatPath)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cw.mu.Lock()
|
cw.mu.Lock()
|
||||||
defer cw.mu.Unlock()
|
|
||||||
if len(data) > cw.offset {
|
|
||||||
cw.win.Addr("$")
|
cw.win.Addr("$")
|
||||||
cw.win.Write("data", data[cw.offset:])
|
cw.win.Write("data", data)
|
||||||
cw.offset = len(data)
|
cw.offset += len(data)
|
||||||
cw.win.Ctl("clean")
|
cw.win.Ctl("clean")
|
||||||
|
cw.mu.Unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in New Issue