add go routine to write function

This commit is contained in:
Russell Stanley 2022-02-04 17:02:18 +10:30
parent 07c2472bdd
commit b0f756a586
1 changed files with 11 additions and 9 deletions

View File

@ -195,15 +195,17 @@ func (tp *turbidityProbe) Write(p []byte) (int, error) {
tp.log.Log(logger.Debug, "found frames", "frames", len(imgs))
// Process video data to get saturation and contrast scores.
go func() {
startTime := time.Now()
res, err := tp.ts.Evaluate(imgs)
tp.log.Log(logger.Debug, "finished evaluation", "total duration (sec)", time.Since(startTime).Seconds())
if err != nil {
tp.log.Error("evaluate failed", "error", err.Error())
return len(p), err
}
} else {
tp.log.Log(logger.Debug, "finished evaluation", "total duration (sec)", time.Since(startTime).Seconds())
tp.contrast = stat.Mean(res.Contrast, nil)
tp.sharpness = stat.Mean(res.Sharpness, nil)
}
}()
default:
return len(p), nil
}