• mlg@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    10 months ago

    I’m actually laughing out loud at the amount of whitespace because thread routine is still executing lmao

  • fxdave@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    10 months ago

    Honestly, I don’t get it.

    Is it about the syntax sugar? Would you like to use callbacks instead?

    Async programming is when you achive concurrency even with one thread. It’s needed. There’s no alternative to this.

  • AggressivelyPassive@feddit.de
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    10 months ago

    I honestly don’t know, why async got so popular. It seems like the entire reason for doing it was that some blokes were hellbent on using JS on a server and couldn’t fathom that a second thread might be a good idea.

    • Lmaydev@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      10 months ago

      A huge amount of time in apps is spent waiting for IO, database or web requests to complete.

      Async prevents locking a thread during this wait.

      If you’re handling a large amount of requests in a web server, for example, it allows other requests to progress while waiting for these operations.

      Threads are also expensive to start and manage.

      Also handling threads manually is a pain in the ass.

    • Nyfure@kbin.social
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      Async is good because threads are expensive, might aswell do something else when you need to wait for something anyways.
      But only having async and no other thread when you need some computation is obviously awful… (or when starting anothe rthread is not easily manageable)

      Thats why i like go, you just tell it you want to run something in parallel and he will manage the rest… computational work, shift current work to new thread… just waiting for IO, async.

    • PlexSheep@feddit.de
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      10 months ago

      Async rust with the Tokio Framework is pretty cool. Need none of that JS bloat for async.

        • deur@feddit.nl
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          10 months ago

          You suck, I hate how your comment was forced “apon” me. Anyone who claims things that they can easily avoid if theyre so opinionated against them are “forced upon” them are always pathetic people.

    • hubobes@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      If you are waiting for IO, why would you block your current thread and not let it do something else? Async does not only exist in JS.

    • Rinox@feddit.it
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      Ok, I’m a c# developer and I use async await quite extensively. Is it different in JS? Or am I missing something?

      • dvlsg@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        10 months ago

        Nah, they’re very similar, really. You generally kick IO heavy stuff you don’t need immediately off to async await.

        There are a few more applications of it in C# since you don’t have the “single thread” to work with like in JS. And the actual implementation under the hood is different, sure. But conceptually they’re similar. Pretty sure JS was heavily influenced by C#'s implementation and syntax.

    • ShortFuse@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      10 months ago

      async/await is just callback() and queueMicrotask wrapped up into a neat package. It’s not supposed to replace multi-threading and confusing it for such is dangerous since you can still stall your main/UI thread with Promises (which async also wraps).

      (async and await are also technically different things, but for the sake of simplicity here, consider them a pair.)

    • masterspace@lemmy.ca
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago

      Because the alternative is a series of ridiculously nested call backs that make code hard to read and manage?

      I honestly can’t fathom how anyone would dislike async programming.

    • idunnololz@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      After using both extensively I would argue async code is easier to read. It has a lot less nesting. And generally easier to read code is a good thing so I’m all for async.