mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-04 10:34:55 +02:00
755ae0ef84
write to deadlock stderr after closing gocui more deadlock checking
32 lines
509 B
Go
32 lines
509 B
Go
package utils
|
|
|
|
import (
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
// This wraps a writer and ensures that before we actually write anything we call a given function first
|
|
|
|
type OnceWriter struct {
|
|
writer io.Writer
|
|
once sync.Once
|
|
f func()
|
|
}
|
|
|
|
var _ io.Writer = &OnceWriter{}
|
|
|
|
func NewOnceWriter(writer io.Writer, f func()) *OnceWriter {
|
|
return &OnceWriter{
|
|
writer: writer,
|
|
f: f,
|
|
}
|
|
}
|
|
|
|
func (self *OnceWriter) Write(p []byte) (n int, err error) {
|
|
self.once.Do(func() {
|
|
self.f()
|
|
})
|
|
|
|
return self.writer.Write(p)
|
|
}
|