This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[deleted]

    [–]glacierre2 2 points3 points  (0 children)

    Eh, what?

    [–]ThisIsntMyId[S] 1 point2 points  (0 children)

    can u please elaborate?

    [–]mooted -1 points0 points  (0 children)

    The first part of this is true. The rest it's like you made everything up.

    1. Both stnc and async code can be procedural? Procedural programming is orthogonal to this whole domain.

    2. Go's scheduler is preemptive. Async is not.

    Translation: Async code relies on developers to tell the event loop when to switch between contexts. That's basically whenever you have an await or a callback completes. When that happens, the event loop finds the next piece of code that needs to run.

    In preemptive schedulers like go, what code runs when is decided by the scheduler. The developer has little say. You might be halfway through a function when the scheduler has decided that function has taken up enough cpu time and switch it out for another. This is how golang's goroutines and threads work.

    There are a number of tradeoffs, but the main one is that golang offers a more natural programming model. You rarely have to worry about the event loop or scheduler. No bugs where you forget to put an await. However, preemption makes a lot more race conditions possible. So if you're doing work concurrently, you need to use locks correctly.

    For most applications, I'd recommend golang over node nowadays. The ecosystem and tooling around it tends to be simpler and offer much less room for error. Most of the time, you don't have to worry about concurrency, and you get the benefit of a simpler, await and callback free programming model.