Go (Golang) Fan-In Fan-Out Pattern

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 31

  • @cheenamaejafar
    @cheenamaejafar 2 года назад

    Thanks for this tutorial. This channel is the most underrated Go tutorial on yt. Please keep it up.

  • @Tay74514
    @Tay74514 9 дней назад

    ❤ thank you bro

  • @harry-cee
    @harry-cee 2 года назад +1

    The most detailed explanation that exists on the subject on youtube. At timestamp 17:20, To block the func fanIn from returning, You have moved the `wg.Wait()` in a separate Go Routine. Could you please explain, Why is that?

    • @a_maxed_out_handle_of_30_chars
      @a_maxed_out_handle_of_30_chars 2 года назад

      I've same question

    • @harry-cee
      @harry-cee 2 года назад +2

      @@a_maxed_out_handle_of_30_chars I guess the "fanIn" function must return immediately with the newly created channel such that the "main" block starts reading concurrent writes on it. However, main function would still be held up until all go routines complete which is what we want.

    • @hrishekessaraghu5778
      @hrishekessaraghu5778 Год назад

      so using the Fanout and fanin pattern the order of data is not maintained? Is there any way to print the data with same order like how it was in the csv file?

    • @hrishekessaraghu5778
      @hrishekessaraghu5778 Год назад

      @@harry-cee so using the Fanout and fanin pattern the order of data is not maintained? Is there any way to print the data with same order like how it was in the csv file?

    • @harry-cee
      @harry-cee Год назад

      @@hrishekessaraghu5778 As such with any concurrent and parallel processing, You ideally want each job to finish and clear as quickly it can. There shouldn't be any reason to hold out routines for other jobs to finish. You might want to consider an aggregator/ sorter function to take all the results and sort them as you desire before writing to a csv, for instance.

  • @sundaypodcom
    @sundaypodcom 2 года назад

    It was quite intuitive!

  • @rabingaire
    @rabingaire 3 года назад +1

    Great video as usual thank you

  • @Levelord92
    @Levelord92 Год назад

    How is it better than, for example, just transforming regular slice of City structs? Is it faster?

    • @derdere7803
      @derdere7803 Год назад

      was gonna ask the same. If someone can benchmark both cases, I want to find out as well. But even if there is no difference, it's a good example for teaching purposes.

  • @efrainalvarez9013
    @efrainalvarez9013 3 года назад

    greate video, helpfull to understanding concurrency

  • @baxiry.
    @baxiry. Год назад

    useful information Thanks

  • @eant1234
    @eant1234 3 года назад +1

    Hey this a great tut. At about 18.30 you put wg.Wait in an anonymous goroutine func. Why is that? I 'm thinking that wg,Wait blocks anyway?

    • @BhanuReddyputtareddy
      @BhanuReddyputtareddy 3 года назад +2

      wg.Wait has to be in separate routine becuase since we are sending to out channel
      and no one will be reading out from channel if wg.Wait is not inside go routine
      as wg.Wait will block main routine until all go routines are completed wg.wait
      has to be in separate go routine so that it is read from out channel other wise all routines will get blocked

  • @rennygalindez
    @rennygalindez 2 года назад

    Awesome! 👍

  • @victornoagbodji
    @victornoagbodji 3 года назад

    😊 🙏 😊
    thank you so much for sharing.
    this taught me a few things.

    • @GolangCafe
      @GolangCafe  3 года назад

      Thanks Victor happy that you learned something new

  • @skuldd
    @skuldd 2 года назад

    Amazing!

  • @hrishekessaraghu5778
    @hrishekessaraghu5778 Год назад

    so using the Fanout and fanin pattern the order of data is not maintained? Is there any way to print the data with same order like how it was in the csv file?

    • @derdere7803
      @derdere7803 Год назад

      you can give an id to each city and when done with the all the channels, you can create a slice and put them in their initial order. For that you need to know the length of the csv file. One way you can do that is while running the first go routine count the lines at the same time and send that number in a countChannel. In the main then, you can read from that countChannel and create the final results slice with make([]int, 0, count)

  • @myrachoantonio8832
    @myrachoantonio8832 3 года назад

    thank you for the video

  • @LNMLucasMasiero
    @LNMLucasMasiero 2 года назад

    thank you, very clear!

  • @conor7728
    @conor7728 3 года назад

    thanks, great vid. Are there any fan out patterns where wokers don't have to compete i.e the fan out channel blocks until all workers have consumed the message.

    • @yjawhar
      @yjawhar 11 месяцев назад

      Depending on the circumstances, contexts might be used for this purpose.

  • @chifundomulonyiwa1499
    @chifundomulonyiwa1499 3 года назад

    We really like you bro

    • @GolangCafe
      @GolangCafe  3 года назад

      Thanks for the support bro

  •  2 года назад

    great tutorial thank you!