github.com/getgauge/gauge@v1.6.9/parser/specFileCollection.go (about)

     1  // Copyright 2019 ThoughtWorks, Inc.
     2  
     3  /*----------------------------------------------------------------
     4   *  Copyright (c) ThoughtWorks, Inc.
     5   *  Licensed under the Apache License, Version 2.0
     6   *  See LICENSE in the project root for license information.
     7   *----------------------------------------------------------------*/
     8  
     9  package parser
    10  
    11  import (
    12  	"fmt"
    13  	"sync"
    14  )
    15  
    16  type specFileCollection struct {
    17  	mutex     sync.Mutex
    18  	index     int
    19  	specFiles []string
    20  }
    21  
    22  func NewSpecFileCollection(s []string) *specFileCollection {
    23  	return &specFileCollection{specFiles: s}
    24  }
    25  
    26  func (s *specFileCollection) Next() (string, error) {
    27  	s.mutex.Lock()
    28  	defer s.mutex.Unlock()
    29  	if s.index < len(s.specFiles) {
    30  		specFile := s.specFiles[s.index]
    31  		s.index++
    32  		return specFile, nil
    33  	}
    34  	return "", fmt.Errorf("no files in collection")
    35  }