func _reqDoPage(req *drive.FilesListCall, hidden bool, promptOnPagination, nilOnNoMatch bool) *paginationPair { filesChan := make(chan *File) errsChan := make(chan error) throttle := time.Tick(1e8) go func() { defer func() { close(errsChan) close(filesChan) }() pageToken := "" for pageIterCount := uint64(0); ; pageIterCount++ { if pageToken != "" { req = req.PageToken(pageToken) } results, err := req.Do() if err != nil { errsChan <- err break } iterCount := uint64(0) for _, f := range results.Items { if isHidden(f.Title, hidden) { // ignore hidden files continue } iterCount += 1 filesChan <- NewRemoteFile(f) } pageToken = results.NextPageToken if pageToken == "" { if nilOnNoMatch && len(results.Items) < 1 && pageIterCount < 1 { // Item absolutely doesn't exist filesChan <- nil } break } <-throttle if iterCount < 1 { continue } if promptOnPagination && !nextPage() { filesChan <- nil break } } }() return &paginationPair{filesChan: filesChan, errsChan: errsChan} }
func reqDoPage(req *drive.FilesListCall, hidden bool, promptOnPagination bool) chan *File { fileChan := make(chan *File) throttle := time.Tick(1e7) go func() { defer close(fileChan) pageToken := "" for { if pageToken != "" { req = req.PageToken(pageToken) } results, err := req.Do() if err != nil { fmt.Println(err) break } iterCount := uint64(0) for _, f := range results.Items { if isHidden(f.Title, hidden) { // ignore hidden files continue } iterCount += 1 fileChan <- NewRemoteFile(f) } pageToken = results.NextPageToken if pageToken == "" { break } if iterCount < 1 { <-throttle continue } if promptOnPagination && !nextPage() { fileChan <- nil break } } }() return fileChan }