Refactoring #3
@@ -102,31 +102,7 @@ func (s *Source) Close() error {
|
||||
}
|
||||
|
||||
func (s *Source) Next(timeout time.Duration) (Frame, error) {
|
||||
for {
|
||||
g, err := s.reader.GetGrain(s.idx, timeout)
|
||||
switch {
|
||||
case err == nil:
|
||||
f := Frame{
|
||||
Index: g.Index,
|
||||
Width: s.width,
|
||||
Height: s.height,
|
||||
Stride: s.stride,
|
||||
Size: g.GrainSize,
|
||||
Invalid: g.Invalid(),
|
||||
Payload: g.Payload,
|
||||
}
|
||||
s.idx++
|
||||
return f, nil
|
||||
case errors.Is(err, mxl.ErrTimeout):
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
case errors.Is(err, mxl.ErrOutOfRangeEarly):
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
case errors.Is(err, mxl.ErrOutOfRangeLate):
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
default:
|
||||
return Frame{}, fmt.Errorf("GetGrain: %w", err)
|
||||
}
|
||||
}
|
||||
return s.NextCtx(context.Background(), timeout)
|
||||
}
|
||||
|
||||
func (s *Source) NextCtx(ctx context.Context, timeout time.Duration) (Frame, error) {
|
||||
|
||||
Reference in New Issue
Block a user