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)) tp.log.Log(logger.Debug, "found frames", "frames", len(imgs))
// Process video data to get saturation and contrast scores. // Process video data to get saturation and contrast scores.
startTime := time.Now() go func() {
res, err := tp.ts.Evaluate(imgs) startTime := time.Now()
tp.log.Log(logger.Debug, "finished evaluation", "total duration (sec)", time.Since(startTime).Seconds()) res, err := tp.ts.Evaluate(imgs)
if err != nil { if err != nil {
tp.log.Error("evaluate failed", "error", err.Error()) 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.contrast = stat.Mean(res.Contrast, nil)
tp.sharpness = stat.Mean(res.Sharpness, nil) tp.sharpness = stat.Mean(res.Sharpness, nil)
}
}()
default: default:
return len(p), nil return len(p), nil
} }