The Dangers Of Promise.all()

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024
  • Please just use Promise.allSettled()
    Keywords JAVASCRIPT JS TS TYPESCRIPT ASYNC SYNC ASYNCHRONOUS SYNCHRONOUS PROMISES
    ALL MY VIDEOS ARE POSTED EARLY ON PATREON / t3dotgg
    Everything else (Twitch, Twitter, Discord & my blog): t3.gg/links

ความคิดเห็น • 223

  • @Cableguyyy
    @Cableguyyy ปีที่แล้ว +308

    This video left me fulfilled. Thanks Theo

    • @meqativ
      @meqativ ปีที่แล้ว +4

      replies[0].content

    • @frankkuipers2024
      @frankkuipers2024 ปีที่แล้ว

      @@meqativreplies?.at(-1)?.content

    • @johnddonnet5151
      @johnddonnet5151 ปีที่แล้ว +2

      @@meqativ replies undefined

    • @meqativ
      @meqativ ปีที่แล้ว

      @@johnddonnet5151
      const replies = [
      {
      user: "meqativ",
      content: "replies[0].content",
      },
      {
      deleted: true,
      },
      {
      user: "johnddonnet5151",
      content: "replies undefined",
      mentions: { user: "meqativ", short: null, },
      },
      {
      user: "meqativ",
      content: [Circular *1],
      mentions: { user: "johnddonnet5151", short: null, },
      },
      ];
      replies.at(-1).content

    • @BikoGames
      @BikoGames ปีที่แล้ว

      @@johnddonnet5151 if (Array.isArray(replies))

  • @tuomaskoivistoinen6476
    @tuomaskoivistoinen6476 ปีที่แล้ว +176

    Promise.all is good for doing multiple queries with no side effects where you need all to succeed before the next step. You could do all settled and add retry logic but I’d rather have it in the work function or have the whole thing retried instead

    • @awmy3109
      @awmy3109 ปีที่แล้ว +5

      Exactly. Devs just worry about BS these days 😂

    • @kartashuvit4971
      @kartashuvit4971 ปีที่แล้ว +3

      wouldn't it be better to start a transaction instead

    • @tuomaskoivistoinen6476
      @tuomaskoivistoinen6476 ปีที่แล้ว

      @@kartashuvit4971 that question is a bit orthogonal to how you handle promises. If a transaction would prevent significant bugs then yes, otherwise you get better performance committing a single statement at a time.

    • @nikensss
      @nikensss ปีที่แล้ว +2

      sounds to me this video is needed because people don't read the documentation thoroughly enough

    • @developersteve1658
      @developersteve1658 ปีที่แล้ว +4

      ​@awmy3109 I think it's that they less worry about bullshit and more and more that the majority use case doesn't require a surgical solution like this.
      If you have some really slow process that runs many times (let's say some api call that costs for time used), it would make sense to try and cache the successful results and retry the failures, because it could save a lot of time and money in the long-term.
      For loading 1kb of json from your own api for a component to render "hello [user]", yeah that can be retried wholesale.

  • @samuelgunter
    @samuelgunter ปีที่แล้ว +152

    if you use all instead of allSettled, this video would be over at 0:10 because that's when the first Exception is thrown

    • @ropoxdev
      @ropoxdev ปีที่แล้ว +1

      Haha

    • @Notoriousjunior374
      @Notoriousjunior374 ปีที่แล้ว +1

      You should have a function that catches that error, do whatever you want with it, null, undefined or whatever. Then it wouldn’t be a problem?

    • @avidrucker
      @avidrucker ปีที่แล้ว

      Also interested to know

  • @robgioeli
    @robgioeli ปีที่แล้ว +100

    I’m glad you got this all settled, thanks Theo 😉

  • @Alec.Vision
    @Alec.Vision ปีที่แล้ว +68

    4:09 Bruh, that's what Exclude is for. The best thing about Exclude is that it will exclude anything that EXTENDS the second type param... so you can exclude a whole object type from a discriminated union by specifying only the discriminating property. You don't have to know the types, just the difference.

    • @Glyra12
      @Glyra12 ปีที่แล้ว +5

      didnt knew about this
      nice one

    • @kevinmitchell6141
      @kevinmitchell6141 ปีที่แล้ว

      Could you give an example of how you use this?

    • @LLF1234
      @LLF1234 ปีที่แล้ว

      @@kevinmitchell6141 If he doesn't, ChatGPT probably does

    • @pellyryu2344
      @pellyryu2344 6 หลายเดือนก่อน

      nice tip thanks

  • @gosnooky
    @gosnooky ปีที่แล้ว +11

    To be fair the "^" operator being XOR and not exponent is common to most languages? As for the topic at hand, I'm guilty. I use Promise.all all the time.

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว +2

      I believe it's the standard. Most languages have something like Math.pow() or pow() instead of **.

  • @EvanBoldt
    @EvanBoldt ปีที่แล้ว +30

    Seems like another example of how returning errors results in better error handling than throwing errors.

    • @alexandrucaraus233
      @alexandrucaraus233 ปีที่แล้ว +2

      Throwing is more OOP, returning is more functional approach. TS supports both, so it all depends how and when you use it.

    • @bryanleebmy
      @bryanleebmy ปีที่แล้ว +17

      @@alexandrucaraus233 Nothing about throwing or returning is inherently OOP or functional. Throwing is just the model most commonly used by Java, which happens to be the most widely taught OOP language. In an alternate universe, returning errors or result types could have been the standard way of doing things in Java. OOP != throwing.

    • @kartashuvit4971
      @kartashuvit4971 ปีที่แล้ว +3

      That's why I'm slowly falling in love with Go

    • @alexandrucaraus233
      @alexandrucaraus233 ปีที่แล้ว +1

      @@bryanleebmy yes, java, c#, c++ and all other other OOP languages use more the throwing approach, and all other pure functional prefer returning values. So blue!=green, like I said :D.

    • @felipeandrade6629
      @felipeandrade6629 5 หลายเดือนก่อน

      Said the Go developer, lol

  • @theoneandonlymeshe9174
    @theoneandonlymeshe9174 ปีที่แล้ว +6

    “I hate JavaScript” ~ Theo, Aug 2023 1:34

  • @alanscodelog
    @alanscodelog ปีที่แล้ว +5

    I usually use .all and catch in the entry promises and handle any errors and cleanup there and return or push the errors to an array (I find this nicer and more flexible than allSettled). The final .all then only serves to send off /format the errors if needed, or to take the final decision on what to do, not handle the errors themselves.

  • @Xe054
    @Xe054 ปีที่แล้ว +5

    I love this type of content where you share new discoveries about a language. Please make more videos like this.

  • @Voidstroyer
    @Voidstroyer ปีที่แล้ว +5

    Nothing dangerous about promise.all if you know what it does (You might argue with me because I said "if you know what it does" but I say that because the function itself is not dangerous, it's the misuse of the function that is dangerous). Promise.all requires all functions to resolve otherwise nothing is returned (which does resolve in discarded work being done). Promise.allSettled is a good alternative though but if the requirement is that all promises MUST resolve (and you don't have a retry mechanism which could potentially also cause other complexities because endless retries would cause your program to hang) then promise.all is the preffered choice.

  • @AlexSpieslechner
    @AlexSpieslechner ปีที่แล้ว +3

    summoning ts wizard matt to make a video on this type

  • @MKorostoff
    @MKorostoff ปีที่แล้ว +6

    Great video, but for the most part, I want Promise.all to reject if a single underlying promise rejects. For instance, I was recently writing some code that split PDFs into chunks for search indexing. If one single page cannot be chunked, I don't want to store incomplete data, I want to show a message like "example.pdf failed on page X." Promise.all is essentially like a database transaction in that way, and very convenient for that purpose (though I agree, allSettled has many great use cases).

    • @xinaesthetic
      @xinaesthetic ปีที่แล้ว

      Do you have a strategy for cancelling other tasks when one fails?

    • @MKorostoff
      @MKorostoff ปีที่แล้ว

      @@xinaesthetic like if you had promises foo and bar, and you want to init them at the same time, then cancel bar if foo fails? Personally, I wouldn't, I'd just let bar finish.

    • @xinaesthetic
      @xinaesthetic ปีที่แล้ว

      @@MKorostoff fair enough. No point coding it when you don't need it. In a situation where it did matter I suppose I'd probably have some shared reference to a bit of state that flags if the operation should be cancelled, but not sure what particular patterns there are that might be good to know.

  • @RealDrDoom
    @RealDrDoom ปีที่แล้ว +2

    Maybe this is an anti-pattern but what if you catch inside the promises? If there's an error return null, otherwise return the result. That way the promises always resolve and we can filter out results after

  • @karamuto1565
    @karamuto1565 ปีที่แล้ว +1

    I am more into observables by now. There I have multiple choices to handle multi asyncs and it feels easier.

  • @jewbarrymore_
    @jewbarrymore_ 5 หลายเดือนก่อน

    It was super hard not to notice and resist commenting, but why is waitFor declared as async? Seems kinda extra to wrap the return value when you're already returning a promise? Obviously, js handles it behind the scenes gracefully, but still, there's no await used inside.

  • @TJKlimoski
    @TJKlimoski 6 หลายเดือนก่อน

    I actually just used promise.all in a project that to me was appropriate. Essentially I'm running two async functions in parallel that return an array of values. Once I get back both arrays I compare the two arrays and keep the values that are shared between the two. If one promise rejects (which only happens because they found no values to return in their array) I don't need to know what the returned values in the other async function will be because I know there will be no matching values for me to pull. So the fact that it jumps to the catch statement, and I don't get the values for the other promises, all work out.

  • @john.dough.
    @john.dough. ปีที่แล้ว

    1:06 -> the carrot operator `^` is bitwise OR in JavaScript. You probably wanted Math.pow().
    nvm, you caught it.

  • @umuden
    @umuden ปีที่แล้ว +8

    Yes, the error behavior isn't too inferable. Once, instead of reading the docs, I wrote my own makeConsecutively function. Which was fine.

  • @ColinRichardson
    @ColinRichardson 7 หลายเดือนก่อน

    New Title = I used the wrong method for what I really want.. but what I want is not what 95% of everyone else wants.

  • @trappedcat3615
    @trappedcat3615 ปีที่แล้ว +2

    I don't get it. I'm still awaiting the catch. Let me know when this is all settled.

    • @alexandrucaraus233
      @alexandrucaraus233 ปีที่แล้ว +1

      All is settled, nothing to catch, go home :D.

  • @kasparsiricenko2240
    @kasparsiricenko2240 ปีที่แล้ว

    Well kinda made up problem. If this is your requirements then you might not need promise all after all.

  • @guilhermegoncalves6743
    @guilhermegoncalves6743 6 หลายเดือนก่อน

    Promise.all is good when youre using puppeteer. Great video!

  • @elevyg
    @elevyg ปีที่แล้ว +1

    It is easier to check if the item of the result has value as key, then you know that the status is fulfilled

  • @pelle4971
    @pelle4971 ปีที่แล้ว +1

    How might our understanding and application of asynchronous functions change if we were to prioritize clarity and predictability of outcomes over simplicity or convention in our coding practices?

  • @dickson710
    @dickson710 ปีที่แล้ว +5

    If people are interested for the partial success result from the promises, you can wrap the async call with a function which have a catch block inside. Then you may still get the results even some are failed.

  • @Bluesourboy
    @Bluesourboy ปีที่แล้ว +5

    I have this issue in some production apps that were not written by me that this will fix. Theo you are a godsend!

  • @SkyaTura
    @SkyaTura ปีที่แล้ว

    The type issue couldn't be solved by using Exclude?

  • @festusyuma1901
    @festusyuma1901 ปีที่แล้ว +1

    If you use a for loop instead of a filter, you'll get the correct typing

  • @appuser
    @appuser ปีที่แล้ว +1

    I haven't finished the video yet, but I'm going to guess most of the time taking a less FP approach and using "for...in" within an already async function is the recommendation coming up, rather than managing the nesty confusion of Promise.all

    • @appuser
      @appuser ปีที่แล้ว

      I was so wrong and learned something useful.

  • @dtinth
    @dtinth ปีที่แล้ว +12

    4:54 - When seeing `.filter` followed by `.map`, using `.flatMap` will usually result in a cleaner code: `results.flatMap(r => r.status === 'fulfilled' ? [r.value] : [])`
    When you use flatMap, filtering and mapping is done in a single step, so there is no loss of type information between these 2 steps.

    • @NickServ
      @NickServ ปีที่แล้ว +1

      True, but transduce also fixes this problem without introducing intermediate arrays, which will use more memory and power to merge.

    • @magne6049
      @magne6049 ปีที่แล้ว +1

      @@NickServ which transducers library do you recommend for JS?

  • @stevenhe3462
    @stevenhe3462 ปีที่แล้ว

    Because JavaScript Promises are fucking eager.

  • @ziadx3
    @ziadx3 2 หลายเดือนก่อน

    thank god typescript fixed this filter issue

  • @DevinBidwell
    @DevinBidwell 7 หลายเดือนก่อน

    Sorry did you say Exception? I think you mean Error ;)

  • @lengors7327
    @lengors7327 2 หลายเดือนก่อน

    The filter issue was solved with TS5.5 🎉

  • @alexaka1
    @alexaka1 ปีที่แล้ว

    This behavior makes me like RxJS.

  • @rudro314
    @rudro314 9 หลายเดือนก่อน

    thanks for letting me know how bad js is

  •  10 หลายเดือนก่อน

    Basically if your requirement is to process a bunch of steps sequentially, which means one after the other, please forget Promise.all because it process everything CONCURRENTLY.

  • @danielchukwu524
    @danielchukwu524 5 หลายเดือนก่อน

    I can't reject this one. God bless

  • @Aetherius218
    @Aetherius218 ปีที่แล้ว +4

    You could also implement error catching in your asynchronous function (e.g., WORK) and have it return the potentially caught error. Then you can filter the returned array by instanceof Error

    • @Notoriousjunior374
      @Notoriousjunior374 ปีที่แล้ว

      This, I don’t know what’s wrong with the limited amount of creativity in devs these days.

    • @Alec.Vision
      @Alec.Vision ปีที่แล้ว

      Lol, Promise.all(promises.map(p=>p.catch(e=>e)))
      Can I haz utoob job plz?

  • @Holdino_
    @Holdino_ ปีที่แล้ว +1

    I've been awaiting this video

  • @DryBones111
    @DryBones111 ปีที่แล้ว

    The typing on the settled promise is so gross 😭

  • @spicybaguette7706
    @spicybaguette7706 ปีที่แล้ว

    JS error handling in general sucks IMHO, especially with promises. Even with typescript you have no way of knowing if a function could throw and what it would throw, I hate it

  • @sobanya_228
    @sobanya_228 ปีที่แล้ว

    I use it with something that's not an array. When you request multiple things, but definitely need all of it. An array api in that situation is kinda bad, I even defined a dictionary version of Promise.all, where you give names to each entry.

  • @code.smiles
    @code.smiles ปีที่แล้ว

    Sorry for the *chain* of puns...

  • @owenwexler7214
    @owenwexler7214 ปีที่แล้ว

    Don’t worry, the Promise puns will never not be funny… although I’m sure some people will… await the day when this isn’t true.

  • @mattmmilli8287
    @mattmmilli8287 7 หลายเดือนก่อน

    Use await in a for-in loop(you can indeed!) to do them sequentially and promise.all for all at once

  • @d3vilm4ster
    @d3vilm4ster ปีที่แล้ว

    Well not all is Settled in JS async yet

  • @valenciawalker6498
    @valenciawalker6498 5 หลายเดือนก่อน

    Thank you very helpful.

  • @xaviersavinon5851
    @xaviersavinon5851 ปีที่แล้ว +3

    Thanks, I didn't know that allSettled existed.
    Before this video, I only used Promise.All like this:
    The function WORK would be an async func with a try/catch so, if the promise got resolved would returned the value if not returned a null. After that filter the array of nulls.

  • @snatvb
    @snatvb ปีที่แล้ว

    promises is sucks because they are not lazy and not cancellable
    and this might leads to unexpected results, data-race in async useEffect in react for example

  • @IvanRandomDude
    @IvanRandomDude ปีที่แล้ว +1

    Thanks F#

  • @_worksonmymachine
    @_worksonmymachine ปีที่แล้ว

    I'm just here for the puns.

  • @sn0wb0ardfreak72
    @sn0wb0ardfreak72 ปีที่แล้ว

    promise.All() seems more reasonable in a serverless backend env during boot / initialization (eg. AWS SSM)

  • @joshrogan3577
    @joshrogan3577 ปีที่แล้ว

    Is it fine to do promise.all with tanstack query mutateAsync? Say I need to make 5 separate independent mutations on button click.

  • @pankuka23
    @pankuka23 ปีที่แล้ว

    If I need all results to succeed, and I don't want to keep it running on failed as .all does, I just use an async for loop - works wonders ;)

  • @yofish101
    @yofish101 ปีที่แล้ว

    Yavascript folks…

  • @bhardwajthummar9313
    @bhardwajthummar9313 ปีที่แล้ว +1

    Hail allsettled() !!!!!

  • @schlopping
    @schlopping ปีที่แล้ว

    honestly this is the best argument I've seen for a Result type, and it wasn't even intended.

  • @alexanderpedenko6669
    @alexanderpedenko6669 ปีที่แล้ว

    Who is this video for, who immediately started writing on React without learning JS basics?

  • @dev1333
    @dev1333 ปีที่แล้ว

    oh no... dont do this to me theo

  • @Tszyu01
    @Tszyu01 ปีที่แล้ว

    I usually use a library like p-all or p-limit to also ensure promise all runs with a specified amount of concurrency.

  • @vncntjms
    @vncntjms ปีที่แล้ว

    I prefer to just retry everything. That's the reason why I put them all together in one promise in the first place.

  • @ellisgl
    @ellisgl ปีที่แล้ว

    I just keep thinking of the song "Promises" by Fugazi...

  • @miguelemmara5046
    @miguelemmara5046 11 หลายเดือนก่อน

    its 'all or nothing'

  • @klausburgersten
    @klausburgersten ปีที่แล้ว

    wdym hard to work with async stuff in js? have you tried to do this in python?

  • @kartashuvit4971
    @kartashuvit4971 ปีที่แล้ว

    The type issue is actually easy to solve
    npm uninstall -g typescript

  • @hanes2
    @hanes2 ปีที่แล้ว

    if u think async is hard in javascript. well.. it's freaking pain in other languages, even just Python it's quite a nightmare compared to Javascript.

    • @magisteryura
      @magisteryura 7 หลายเดือนก่อน

      python is a pain as a whole

  • @danypell2517
    @danypell2517 ปีที่แล้ว

    another gem

  • @3ventic
    @3ventic ปีที่แล้ว

    Isn't the .filter and .value issue one of those things that ts-reset fixes?

  • @cryptoaddict6715
    @cryptoaddict6715 ปีที่แล้ว

    Thank you

  • @williamdrum9899
    @williamdrum9899 ปีที่แล้ว

    "Don't make promises you can't keep" seems to be the moral here

  • @MrJester831
    @MrJester831 ปีที่แล้ว

    Futures > Promises because polling can be halted

  • @flatmapper
    @flatmapper ปีที่แล้ว

    Great

  • @RTWeaver
    @RTWeaver ปีที่แล้ว

    I use it when building my test environment on the backend. I don't really care if the server or database failed to standup, if either of them fails then its pointless to run the test suite. Same with performing a bunch of bulkCreates with sequelize. If one of the bulkCreates fails then the database is corrupted anyway and I'm going to have to find out whats wrong and fix it regardless so it doesn't matter if the promises still run in the background or send back results.

    • @Fernando-ry5qt
      @Fernando-ry5qt ปีที่แล้ว

      The bulk case if you work with a bunch of operations of that nature you might use a Sagas pattern and revert/delete the corrupted data and retry it in some cases, but yeah I get what you mean

  • @StephenRayner
    @StephenRayner ปีที่แล้ว

    Damn 😮

  • @Nackenschelle
    @Nackenschelle ปีที่แล้ว

    splendid moustache, theo 🤝🏼

  • @paulomattos6753
    @paulomattos6753 ปีที่แล้ว

    Promise ALL is the best for select queries

  • @Kay8B
    @Kay8B ปีที่แล้ว

    I only used promise.all when theres a dependancy chain, a relies on b relies on c. If A failed we dont want to continue. Otherwise I agree settled for everything else.

    • @t3dotgg
      @t3dotgg  ปีที่แล้ว

      Wouldn’t you need to await in sequence if they are dependent?

    • @Kay8B
      @Kay8B ปีที่แล้ว

      @@t3dotgg Right my example wasnt clear, they would rely on eachother or another dependant requires all 3. Not sequentially. not in fact a proper "chain" more like a web

  • @luc122c
    @luc122c ปีที่แล้ว

    I find using a promise pool is a good balance. They usually return results and errors as separate objects, and have other features such as setting concurrency

  • @possumkeys
    @possumkeys ปีที่แล้ว +2

    Use case: Start up app requirements being fetched in calls. If any fails, we need to start all over again.

    • @t3dotgg
      @t3dotgg  ปีที่แล้ว +1

      Wouldn't it be nice to know WHICH failed?

    • @garretmh
      @garretmh ปีที่แล้ว

      @@t3dotgg You can add catch handlers to the individual promises and benefit from the short-circuiting behavior.

    • @possumkeys
      @possumkeys ปีที่แล้ว

      @@t3dotgg not really, I can't see that on network debugging. It's all strictly required so we start all over again.

  • @bozhidarmanev6772
    @bozhidarmanev6772 ปีที่แล้ว

    Theo is close to embracing a properly typed language!

    • @johnmcparland3277
      @johnmcparland3277 ปีที่แล้ว

      "JS Dev discovers Result and/or Option" is my favorite genre of programming video

  • @kylegilbert5089
    @kylegilbert5089 ปีที่แล้ว +2

    Wow, this is actually an issue in one of my apps and I wasn't sure what the problem was. Ty Theo.

  • @munnakumarbarnwal1694
    @munnakumarbarnwal1694 ปีที่แล้ว

    Great video 😍, Thanks

  • @truepicksyt3323
    @truepicksyt3323 ปีที่แล้ว

    But I heard never settle

  • @tobafett2873
    @tobafett2873 ปีที่แล้ว

    solid vid, good stuff.

  • @errormaker1
    @errormaker1 ปีที่แล้ว

    That is unsettling

  • @benkogan1579
    @benkogan1579 ปีที่แล้ว +6

    Another thing is that the Promise concurrency functions are only useful for IO / network related tasks, since the requests are in flight in parallel. However, if you just have a very expensive task computationally, splitting it up and Promise.alling it wont speed it up at all, since JS is single-threaded and it will only ever work on one task at a time. If, however, you used multiple threads operating on multiple cores, then it would make sense.

    • @aredrih6723
      @aredrih6723 ปีที่แล้ว +3

      You kind always turn computation heavy task into io with webWorker. It just requires a lot more setup (create worker, send relevant data, await response from worker)

    • @NickServ
      @NickServ ปีที่แล้ว

      This is a bit of an oversimplification, since while it can result in performance issues compared to threads, single-thread concurrency with delaying Promises until next tick can still improve performance in many situations.

    • @benkogan1579
      @benkogan1579 ปีที่แล้ว

      @@NickServ for example?

    • @aredrih6723
      @aredrih6723 ปีที่แล้ว

      @@NickServ do you mean performance (how fast your code run end to end) or reactivity (how long your code take to react to an event)?
      If reactivity, I agree. If performance, if you have say 1000 lines of code to run to complete a function, splitting it into 10 group of 100 lines won't make things end faster.

    • @NickServ
      @NickServ ปีที่แล้ว

      @@aredrih6723 Both. Promise concurrency still helps with e2e wall time, especially when getting results early with all/race/any.

  • @mehulsharmamat
    @mehulsharmamat ปีที่แล้ว +1

    Just realized one of my production bugs might be due to EXACTLY this. brb checking

  • @aredrih6723
    @aredrih6723 ปีที่แล้ว +2

    I agree on the correctness side but disagree on the efficiency side. If you need _all_ request to complete to perform a task, exiting early is more efficient.
    If you want some retry logic, placing it in the catch handler of each individual promise would allow you to retry immediately instead of having to wait on the slowest to resolve first.
    Also, isn't that be the use case for AbortController ? You tie every request to a signal and as soon as the controller abort, you interrupt as early as possible because the result is no longer required.
    That said, I remember node logging a warning for memory leak for trying to have more than 10 listener to a signal...

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว

      There are cases where all you care about is that the promises are done, not that they succeeded.

    • @wichtel1805
      @wichtel1805 ปีที่แล้ว

      I have exactly such a case in a current project: It does a few async operations in parallel, all of which must resolve. In case of an error, the shared signal cancels the rest. Works very well since we do not need the individual results in case of an error - and an early result is more valuable than having all error messages should more than one fail. But that's clearly very situation dependent.

    • @aredrih6723
      @aredrih6723 ปีที่แล้ว

      @@CottidaeSEA catch(() => {}) is always an option if you don't care what kind of error each promise encounters.
      If you're looking for stat on which action succeeded and which one failed, then yeah, allSettled might fit better.
      Also, at the end of the day, allSettled is just a promise.all with a well chosen then applied to each promise (e.g. .then((e) => ({e, ok:true}), (e) => ({e, ok:false})))

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว

      @@aredrih6723 That is not compatible with await syntax, but yes, that works. Or you could just use allSettled and go on with life.

  • @mananbhatia8575
    @mananbhatia8575 ปีที่แล้ว

    Name that vs code theme please

  • @liam7073
    @liam7073 ปีที่แล้ว +1

    Interesting video.
    As useful as it is, JavaScript is such a horrible language for inconsistent rules and syntax.

  • @markclynch
    @markclynch ปีที่แล้ว +1

    Very cool video!

  • @ymi_yugy3133
    @ymi_yugy3133 ปีที่แล้ว

    For interacting with library code is is a good idea. Thanks for pointing it out. In my own code I don’t use exceptions. So promise.all works fine

  • @jkbrodotdev
    @jkbrodotdev ปีที่แล้ว

    Great video, Promise me you leave the puns out next time

  • @StephenRayner
    @StephenRayner ปีที่แล้ว

    There’s an opportunity to make all these suggestions accessible. Something a kin to ESLint warnings / recommendations.
    I’m imagining a plugin that shows brief descriptions of “avoid this” with some if “logical/situation”.
    Then we the community can add their own, vote, attach TH-cam videos.
    So if you write Promise.all you see this video / a code example.

  • @96shahab
    @96shahab ปีที่แล้ว

    @Theo telemetry is a common place for me. I usually push up data in a fire and forget manner and for some metrics (granted, these are not actually all that many) it's better to use all instead of allSettled just because it allows the publishing function to return faster, reducing the time the function has to run. Those promises in the background can fail and it'll just be treated as a missing data point, which for a lot of metric types is actually not critical.

    • @NuncNuncNuncNunc
      @NuncNuncNuncNunc ปีที่แล้ว

      How do you know whether or not you have systemic errors? If you have common errors, your data risks being biased.

    • @96shahab
      @96shahab ปีที่แล้ว

      @@NuncNuncNuncNunc it depends on the metric being sent. Something like network tx and rx for example it's okay if publishing fails once every so often. A user may also select a metric to be non essential and that would be treated the same way. Of course, if every publish fails then that's a different matter that we do look out for, though all we do in that case is log to console, as we can't be sure whether the problem is ours or if the user has something in their config or something like a proxy

  • @mkwpaul
    @mkwpaul ปีที่แล้ว

    Isn't the ^ (caret symbol) bitwise XOR and not exponentiation? From what I can remember ** would be exponentiation.

    • @neoney
      @neoney ปีที่แล้ว

      he says that in the video

  • @ciach0_
    @ciach0_ ปีที่แล้ว

    I Promise to you Theo that this video is going to be resolved for the all-settled users.

  • @jamesm4957
    @jamesm4957 ปีที่แล้ว

    Thats why you choose a language that has a good error handling

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว

      And good typing

    • @magisteryura
      @magisteryura 7 หลายเดือนก่อน

      I still have nightmares about exceptions in Java