Completers (Technique of the Week)

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

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

  • @flutterdev
    @flutterdev  2 месяца назад +10

    Watch more Technique of the Week → goo.gle/FlutterTechnique

  • @adianblabla
    @adianblabla 2 месяца назад +13

    Developing with Flutter for 4 and half years and just started using Completer a few days ago, now this video pops out.
    I am working on package for zebra printers with native SDK, using jnigen package and this technique helped me.
    On native (Kotlin) side I need to make coroutines to be able to print, so I needed a way to handle this on Dart side. I pass a callback class containing operation results (success/error), which I use them to call completer.complete/completer.completeError when the methods finish on Kotlin side. Very handy!

    • @ezhemati
      @ezhemati 2 месяца назад

      It's like use states with bloc or not?

  • @theskyblockman
    @theskyblockman 2 месяца назад +47

    This is such an underused technique! I use it everywhere

    • @jaleger2295
      @jaleger2295 2 месяца назад +9

      Don’t

    • @ToboreOghenevovwerho
      @ToboreOghenevovwerho 2 месяца назад

      Why? Just curious please. I don't know better​@@jaleger2295

    • @lord-jarc
      @lord-jarc 2 месяца назад

      @@jaleger2295 why??

    • @blacktaler
      @blacktaler 2 месяца назад +1

      Unneccessary thing

    • @kantagara
      @kantagara 2 месяца назад +1

      in C# it's also a super common pattern to use it. It's not called like that but it's basically the same pattern

  • @dingus1720
    @dingus1720 2 месяца назад +2

    I've been using Completers non-stop everywhere in my app nowadays. Such a convenient technique

  • @ninojamestan8895
    @ninojamestan8895 2 месяца назад +9

    Remember the KISS principle.
    No need to adjust to this concept if your system does not require you to.

  • @PankajNikam
    @PankajNikam 2 месяца назад +3

    Thanks for the dart pad sample. Its a good move going forward to keep such tricks with a dart pad sample.

  • @alexeygladyshev4718
    @alexeygladyshev4718 2 месяца назад +1

    This is a really useful technique to me. It was helpful for the case when there is some ongoing background task which can be paused or interrupted by user actions. You can also use them instead of bool flags to track if some async task is ongoing/completed. And you can manually pass value with which they resolve.

  • @MirkoGonzalezVasquez
    @MirkoGonzalezVasquez 2 месяца назад +3

    Nice Technique, i would use in the next project.!!

  • @naman2_3
    @naman2_3 Месяц назад

    great platform to learn flutter

  • @jaiswalnitin
    @jaiswalnitin 2 месяца назад +4

    @flutterdev Completer feels like generator function of JavaScript. Am I right ?
    Streams feels like RxJS streams. Nice update.

  • @olteanumihai1245
    @olteanumihai1245 2 месяца назад +1

    This is is a very useful signaling mechanism, it is in many languages with different names(C# - TaskCompletionSource ) and ive made on in JS using promises :D.

  • @kalucky0
    @kalucky0 2 месяца назад +51

    Too bad that when canceling a completer it doesn’t really cancel the task just ignores the result

    • @fmorschel
      @fmorschel 2 месяца назад +1

      I think the only way to force cancelling a process would be something similar to creating an isolate and destroying it when you dont want it anymore. But I'm not sure if that would work (just a guess) and I am sure that would be a big boilerplate for something that we can all just safely ignore today.
      If the call is already resource intensive you would probably be using isolates anyway

    • @Thioby
      @Thioby 2 месяца назад +1

      That's true. Only way to cancel task is wrap it in isolate.

    • @bartekpacia
      @bartekpacia 2 месяца назад +2

      How would that work? Cancellation in Dart must be cooperative. It’s a hard problem, it’s impossible in Dart to “just” cancel an invoked asynchronous function.

  • @hauduedaiduong
    @hauduedaiduong 2 месяца назад +3

    Looks like a promise with the resolve callback isn't it 😄

  • @philosophia5577
    @philosophia5577 2 месяца назад +1

    Craig, I'd love to see a colab with guys at Rive and you, they have their Gamekit written in Flutter...

  • @kingkhan3-d6k
    @kingkhan3-d6k 2 месяца назад +1

    огонь, лучшая подработка в моей жизни

  • @yashabh.sports
    @yashabh.sports 2 месяца назад +7

    Good 👍

  • @-theway5158
    @-theway5158 2 месяца назад +8

    Why would i use this when i can assign simply a bool value if future result is done successfully or not

    • @TekExplorer
      @TekExplorer 2 месяца назад +3

      because you cant await that

    • @s.bamahfoodh
      @s.bamahfoodh 2 месяца назад

      @@TekExplorer
      I’m struggling to understand this concept. If I used a try catch and I set my bool variable simply after the await call, why is that not enough? And how do completers solve the problem

    • @JoeRomano-s8g
      @JoeRomano-s8g 2 месяца назад

      ​@@TekExplorer explain how can you not await it???

    • @scalarcoding
      @scalarcoding 2 месяца назад

      I think the same 😅

    • @fmorschel
      @fmorschel 2 месяца назад

      ​@@JoeRomano-s8g
      The inner property completer.future is a future value of the type you set for the completer. It will always need an await so if it's not complete, it will not leave the "awaiting" part of your code. If it was already completed previously, it resolves immediately as said in the vídeo.

  • @KiraFedoseeva-wd7jd
    @KiraFedoseeva-wd7jd Месяц назад

    good video! but i think it's better if you go live on twitch every day or often and we imitate all of your trades

  • @LordErnie
    @LordErnie 2 месяца назад +1

    @flutterdev What tool did you guys use for the presentation / infographic? I am looking to make some myself in the same style you guys use. It is for my fellow students at my university. Really think it works well.

  • @MrFrostyland
    @MrFrostyland 2 месяца назад +1

    It seems like redundant work. One don't need Completer in this context. One can do simple like that:
    ```dart
    Future init () async {
    return await expensiveSetup();
    }
    ```
    and then
    ```dart
    final obj = MyClass();
    await obj.init();
    obj.doStuff();
    ```

    • @williambryant1672
      @williambryant1672 2 месяца назад +1

      I agree, I don't see how completers add anything new.

    • @barbosa7797
      @barbosa7797 2 месяца назад +1

      overEngineering at his best

    • @leanghenglim
      @leanghenglim Месяц назад +1

      What if you have multiple places that need to await the computation? So if I have a service that needs to be initialised. Then I have 4 other controllers needing this one service. The 4 can all await the completer. But it can't await the init. Why? Because if you run init by 4 controllers, the init process will run 4 times.

  • @drancerd
    @drancerd 26 дней назад

    Thanks Dev team! Now my app doesn't need a button to increment the counter! I wish there was more competent documentation, which would improve the simplistic and pitiful explanation.
    I asked Gemini if ​​he could explain the technique better, applying it to real cases with isolate, etc.
    s/He told me that my question offended h_er/im and closed the chat.

  • @zedicustenebres8031
    @zedicustenebres8031 2 месяца назад

    this is so smart omg thanks !!

  • @LiteSolo
    @LiteSolo 2 месяца назад

    That's exactly what I desired :)

  • @Coco-x8p
    @Coco-x8p Месяц назад

    Реал рабочая связка, спасибо бро

  • @구글구글-t3x
    @구글구글-t3x 2 месяца назад

    on second usecase is completer is used for ensure input value’s operation is asynchronously finished until output stream’s emit??

  • @rnp0728
    @rnp0728 2 месяца назад

    Hey guys, I have to implement video calling using flutter for 3 platforms (web, android, ios ) any suggestions which package provides solutions for all 3 platforms.

  • @MirzaMaulanapositivejutsu
    @MirzaMaulanapositivejutsu 2 месяца назад

    But why don't we just use a nullable variable and then initialize method future to start using the variable?

  • @kamranbashir4842
    @kamranbashir4842 2 месяца назад +1

    I will just use a bool my class and an infinite loop over the implementation

  • @FikriHaikal-he4bg
    @FikriHaikal-he4bg 2 месяца назад

    So this is similar to Promise

  • @aouadicharaf1038
    @aouadicharaf1038 2 месяца назад

    ❤❤❤

  • @YegresAL
    @YegresAL 2 месяца назад +1

    Some kind of semaphore on steroids ))))

  • @dbred67
    @dbred67 2 месяца назад

    Is this just covering a limitation of Futures? Feel like in JS this is just solved with a new Promise, is there something I'm missing?

    • @dbred67
      @dbred67 2 месяца назад

      "When working with external APIs or libraries that do not return Futures directly, Completers can be used to wrap and adapt these operations into Futures." - So this can be done with Futures but is used when calling code that doesn't return a Future?

  • @mayconjf
    @mayconjf 2 месяца назад

    interessante

  • @Rashidmrck
    @Rashidmrck 2 месяца назад

    😊

  • @AbhishekKumar-bx8gp
    @AbhishekKumar-bx8gp 2 месяца назад

    🎉

  • @ashaangaming
    @ashaangaming 2 месяца назад

    👍

  • @malcomgreen4747
    @malcomgreen4747 2 месяца назад

    Who said flutter id died? Long life flutter

  • @benzaitabderrahamane6338
    @benzaitabderrahamane6338 2 месяца назад

    Your videos are too bright, please use darker colors