Brijesh's Git Server — watchman_client @ ab8299774c357f80bce54ac30891351f625b7c0c

client library for using watchman in go programs

async.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
package watchman_client

import (
	"fmt"
	"os"
	"time"
)

func BackgroundLogSync(seconds int) {
	ticker := time.NewTicker(time.Duration(seconds) * time.Second)
	defer ticker.Stop()

	for range ticker.C {
		if IsLogFileEmpty() {
			fmt.Println("Log file is empty")
		} else {
			fmt.Println("Log file is not empty, but sync function is not built yet")
		}
	}
}

func IsLogFileEmpty() bool {
	file, _ := os.Open("log.json")
	defer file.Close()
	fileInfo, _ := file.Stat()
	return fileInfo.Size() == 0
}