title: Concurrency but only do each task once
body: <pre class="lang-golang prettyprint-override"><code>func main() {
      //switch statement here that runs grabusernames()
  }
  func grabusernames() {
      f, err := os.OpenFile(&quot;longlist.txt&quot;, os.O_RDONLY, os.ModePerm)
      if err != nil {
          log.Fatalf(&quot;open file error: %v&quot;, err)
          return
      }
      defer f.Close()
  
      rd := bufio.NewReader(f)
      for {
          line, err := rd.ReadString('\n')
          line2 := strings.TrimSpace(line)
          if err != nil {
              if err == io.EOF {
                  break
              }
  
              log.Fatalf(&quot;read file line error: %v&quot;, err)
              return
          }
          tellonym(line2)
      }
  }
  func tellonym(line2 string) {
      threads := 10
  
      swg := sizedwaitgroup.New(threads)
      for i := 0; i &lt; 1000; i++ {
          swg.Add()
          go func(i int) {
              defer swg.Done()
              var client http.Client
              resp, err := client.Get(&quot;https://tellonym.me/&quot; + line2)
              if err != nil {
                  log.Fatal(err)
              }
              defer resp.Body.Close()
              //fmt.Println(&quot;Response code: &quot;, resp.StatusCode)
              if resp.StatusCode == 404 {
                  fmt.Println(&quot;Username&quot; + line2 + &quot;not taken&quot;)
              } else if resp.StatusCode == 200 {
                  fmt.Println(&quot;username &quot; + line2 + &quot; taken&quot;)
              } else {
                  fmt.Println(&quot;Something else, response code: &quot;, resp.StatusCode)
              }
  
          }(i)
      }
  </code></pre>
  <p>The issue with the code above is that it checks the same username 1,000 times
  I'd like it to check each username in the longlist.txt once, but I want to concurrently do it ( it's a long list and I'd like it to be fast</p>
  <p>Current output:</p>
  <pre><code>Username causenot taken
  Username causenot taken
  Username causenot taken
  Username causenot taken
  </code></pre>
  <p>Desired output:</p>
  <pre><code>Username causenot taken
  Username billybob taken
  Username something taken
  Username stacker taken
  </code></pre>