The Dangers Of Promise.all()

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

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

  • @Cableguyyy
    @Cableguyyy Год назад +309

    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.

  • @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 8 месяцев назад

      nice tip thanks

  • @samuelgunter
    @samuelgunter Год назад +153

    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 😉

  • @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 7 месяцев назад

      Said the Go developer, lol

  • @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.

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

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

  • @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 **.

  • @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!

  • @TJKlimoski
    @TJKlimoski 8 месяцев назад

    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.

  • @theoneandonlymeshe9174
    @theoneandonlymeshe9174 Год назад +6

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

  • @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?

  • @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.

  • @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.

  • @AlexSpieslechner
    @AlexSpieslechner Год назад +3

    summoning ts wizard matt to make a video on this type

  • @karamuto1565
    @karamuto1565 Год назад +1

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

  • @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

  • @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.

  • @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.

  • @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

  • @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.

  • @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.

  • @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 ;)

  • @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.

  • @festusyuma1901
    @festusyuma1901 Год назад +1

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

  • @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

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

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

  • @guilhermegoncalves6743
    @guilhermegoncalves6743 8 месяцев назад

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

  • @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

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

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

  •  Год назад

    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.

  • @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

  • @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

  • @daniellchukwu
    @daniellchukwu 7 месяцев назад

    I can't reject this one. God bless

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

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

  • @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?

  • @trappedcat3615
    @trappedcat3615 Год назад +2

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

  • @ziadx3
    @ziadx3 4 месяца назад

    thank god typescript fixed this filter issue

  • @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.

  • @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

  • @mattmmilli8287
    @mattmmilli8287 8 месяцев назад

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

  • @jewbarrymore_
    @jewbarrymore_ 7 месяцев назад

    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.

  • @ColinRichardson
    @ColinRichardson 9 месяцев назад

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

  • @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.

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

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

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

    Promise ALL is the best for select queries

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

    splendid moustache, theo 🤝🏼

  • @3ventic
    @3ventic Год назад

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

  • @john.dough.
    @john.dough. Год назад

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

  • @lengors7327
    @lengors7327 4 месяца назад

    The filter issue was solved with TS5.5 🎉

  • @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

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

    Well not all is Settled in JS async yet

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

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

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

    Because JavaScript Promises are fucking eager.

  • @valenciawalker6498
    @valenciawalker6498 7 месяцев назад

    Thank you very helpful.

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

    oh no... dont do this to me theo

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

    Thank you

  • @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.

  • @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

  • @mehulsharmamat
    @mehulsharmamat Год назад +1

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

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

    That is unsettling

  • @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.

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

    But I heard never settle

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

    This behavior makes me like RxJS.

  • @bhardwajthummar9313
    @bhardwajthummar9313 Год назад +1

    Hail allsettled() !!!!!

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

    Great video 😍, Thanks

  • @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 9 месяцев назад

      python is a pain as a whole

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

    Futures > Promises because polling can be halted

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

    another gem

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

    I use this helper here to group data by the 'type' field. Could obviously also be a used with a 'status' field.
    export type Visitor = {
    [P in T["type"]]?: Extract[];
    };
    const groupByType = (data: T[]): Visitor =>
    A.groupBy(data, (item) => item.type) as unknown as Visitor;

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

      That `as unknown as Visitor` is a terrible pattern and ugly as hell.

  • @rudro314
    @rudro314 10 месяцев назад

    thanks for letting me know how bad js is

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

    solid vid, good stuff.

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

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

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

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

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

    The typing on the settled promise is so gross 😭

  • @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

  • @code.smiles
    @code.smiles Год назад

    Sorry for the *chain* of puns...

  • @IvanRandomDude
    @IvanRandomDude Год назад +1

    Thanks F#

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

    I'm just here for the puns.

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

    its 'all or nothing'

  • @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.

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

    Great

  • @DevinBidwell
    @DevinBidwell 9 месяцев назад

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

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

    Damn 😮

  • @d.ilnicki
    @d.ilnicki 9 месяцев назад

    You can still await for any of underlying promise in the array. They aren't going anywhere, references are still here.

  • @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.

  • @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

  • @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

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

    Yavascript folks…

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

    Name that vs code theme please

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

    I think it's more about your mental model. `Promise.all` isn't "wait for all of these to settle", it's more of a "treat these all like one big promise". Once you treat it like that, it makes more sense. after using Supabase a lot, I've become a big fan of my async functions being something akin to `function(...args): Promise`. Where they catch themselves and always resolve nicely. That kind of coalesces the behavior of `Promise.all` and `Promise.allSettled`. Either way, it still forces you to consider the error case a lot better

  • @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.

  • @markclynch
    @markclynch Год назад +1

    Very cool video!

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

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

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

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

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

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

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

    I am just a beginner developer, so consider my comment naive if you want. I don't mean any harm here, nor trying to troll just here to learn.
    The inference issue is TS issue and not something Promise.allSettled to be blamed for.
    In cases you need all promises to return a value for further logic to work, I think its quite good. I have used it to fetch data from multiple pages of an API and then combine them for further processing. I don't know any other good way to access data from APIs with pagination.
    I also find the idea that this is a danger of Promise.all, very misleading. Each and every promise.all spec says it will fail if even one of the promises fail. I am not sure there is a reason to push it under the bus for it.

    • @magisteryura
      @magisteryura 9 месяцев назад

      There is really no issue with ts here: TS compiler can't convert arbitrary code into type guard so it does not even try to narrow types. In theory it can narrow type in some cases and auto-magickly deduce that function is effectively type guard, but it too much magick imho