MCPcopy
hub / github.com/micro-editor/micro / init

Function init

internal/buffer/save.go:52–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50var backupRequestChan chan backupRequest
51
52func init() {
53 // Both saveRequestChan and backupRequestChan need to be non-buffered
54 // so the save/backup goroutine receives both save and backup requests
55 // in the same order the main goroutine sends them.
56 saveRequestChan = make(chan saveRequest)
57 backupRequestChan = make(chan backupRequest)
58
59 go func() {
60 duration := backupSeconds * float64(time.Second)
61 backupTicker := time.NewTicker(time.Duration(duration))
62
63 for {
64 select {
65 case sr := <-saveRequestChan:
66 size, err := sr.buf.safeWrite(sr.path, sr.withSudo, sr.newFile)
67 sr.saveResponseChan <- saveResponse{size, err}
68 case br := <-backupRequestChan:
69 handleBackupRequest(br)
70 case <-backupTicker.C:
71 periodicBackup()
72 }
73 }
74 }()
75}
76
77func openFile(name string, withSudo bool) (wrappedFile, error) {
78 var err error

Callers

nothing calls this directly

Calls 3

handleBackupRequestFunction · 0.85
periodicBackupFunction · 0.85
safeWriteMethod · 0.80

Tested by

no test coverage detected