// Async set up multi calls func listen(s *session.Session, next chan *http.Users, calls int, follows float64) { for { select { case users := <-next: i := len(users.Data) - 1 s.IncrementCount() go process(s, users, i, follows) close(next) if calls == utils.MAXPEOPLEGRAB { s.SetNext(users.Pagination.Next_url) return } var batch http.Users nxt := make(chan *http.Users) if users.Pagination.Next_url != "" { log.Println("Getting another batch") batch = http.GetNext(s, users.Pagination.Next_url) } else if follows == 0 { // follows == float64(s.GetLearningStep()) then have a array of functions log.Println("Proceeding to next Step") s.IncrementStep() s.IncrementState() batch = http.GetFollowing(s) follows = float64(s.GetLearningStep()) } else { s.SetNext("") return } go listen(s, nxt, calls+1, follows) nxt <- &batch return } } }