Live data from Hacker News

Go Concurrency vs. RxJS

code.gdnetwork.co

41–50 of 57 posts

Re: Go Concurrency vs. RxJS

#41
post #33

Meanwhile, Java just upped the game of virtual thread with https://mail.openjdk.org/pipermail/jdk-dev/2024-October/0094...

And Dart is just starting next week to implement this which should start putting it into an different category of language entirely.

https://github.com/dart-lang/language/blob/main/working/333%...

Re: Go Concurrency vs. RxJS

#42
post #29

Earlier quoted context omitted.

How do you handle errors when reading from a channel?

data, ok := If ok is false, the channel is closed and data is a zero value.

There is no error here, just a closed channel (e.g. finished successfully is indistinguishable).

You do need to use either two channels (horrible code) or some kind of Result{T,error} wrapper (bad language design).

Re: Go Concurrency vs. RxJS

#43
post #23

Earlier quoted context omitted.

It's also unintuitive in the sense that if you are racing you usually want to discard/stop the other Promises that didn't finish in time. But the only real way to do this is to pass through an AbortController down into whatever networking/IO task (and your own code for that matter) is happening to "cancel" it that way. Otherwise you just end up with the result of the fastest Promise and the rest will continue when th…

I thought the point of using observables over promises is that they have cancellation, and presumably an implementation of race would cancel any slower request (i.e., handle the abort controller automatically)? Is that not the case?

My comment was just on the standard behavior. Not sure when it comes to observables, probably comes down to how you are implementing it. But in general it's impossible to cancel a hanging Promise, you have to have some kind of signalling mechanism that either throws so it rejects or otherwise resolves the Promise chain.

Re: Go Concurrency vs. RxJS

#45
post #16
post #8

Concurrency in Go is overrated; channels are error-prone and not as flexible as they probably could/should be. Though, I honestly find moderately complex Go code far easier to maintain than moderately complex RxJS code, having had both in my career at different times. That said I will admit that sometimes having the RxJS toolkit at your disposal makes solving some problems very easy. It's just that when I construct a…

> Concurrency in Go is overrated; channels are error-prone and not as flexible as they probably could/should be. Channels in Go indeed could be better designed and more extensible. However, they are not the only way to use the Go concurrency. There are usual condition variables, mutexes, etc.

Yep, and frankly I often find myself writing traditional concurrency code in Go. gVisor's checklocks analyzer can be very useful.

Re: Go Concurrency vs. RxJS

#46
post #8

Concurrency in Go is overrated; channels are error-prone and not as flexible as they probably could/should be. Though, I honestly find moderately complex Go code far easier to maintain than moderately complex RxJS code, having had both in my career at different times. That said I will admit that sometimes having the RxJS toolkit at your disposal makes solving some problems very easy. It's just that when I construct a…

I argue CSP is far superior to async/await in almost all cases. In Go errors are explicit and always right there. No weird control flow like you see in javascript.

For everyone else who, like me, needs to think for a moment to remember what CSP stands for: https://en.m.wikipedia.org/wiki/Communicating_sequential_pro...

Re: Go Concurrency vs. RxJS

#47
post #14

JS concurrency is crap. It should be shot and buried in a lead coffin. Debugging async code is pure hell. With Go, you have a normal debugger that can be used to step over the code. You can get normal stack traces for all threads if needed. There is a race detector that can catch most of unsynchronized object access. With JS? You're on your fucking own. You can't find out the overall state of the system ("the list of…

Jesus I wish I could upvote you twice. I am investigating a memory leak due to async code, and there is no way to track it down the cause easily. Even the memory inspectors of Chrome and Firefox are unable to deal with it: they tell me the app is not leaking, the heap size is constant, yet the process RSS itself grows until OOM fires - forcing a manual GC cleans it all so it's not even a leak, but just a terrible interaction between the browser generational GC heuristic and async code.

The workaround? Chuck async code in the bin, in my case replace the await fetch() calls with synchronous XMLHttpRequest requests. Problem solved, even if MDN tries to discourage one to use sync XHR because fetch is the new hotness.

I wish I wasn't so broke that I have to accept JS contract work to pay the bills. JavaScript, and its async/await implementation should be thrown into the flaming sun.

Re: Go Concurrency vs. RxJS

#49
post #36

I always found RxJS fairly awkward. I assumed it was a skill issue (and I still think it is), but gradually learned it for personal and professional projects. It's fine. I avoid it now. I think Go is orders of magnitude better in terms of general concurrency tooling, though I know some people straight up hate it. I've recently started using Effect, the TypeScript library, and I find it's so much better than RxJS as w…

My biggest issue with RxJS is that it is so easy, that you can easily make pretty bad bugs. In particular, you can have a `mergeMap` or a `switchMap`, and with RxJS they are very similar in API. But if you pick the wrong one, it can lead to weird bugs in your application. However, if you would manually program promises and maybe debounce helpers, you would be more likely to program the correct behavior. Still, the ea…

Haha, after all this time I still don’t find RxJS easy unless I’m using it for a common, familiar pattern. I agree otherwise, though. It’s definitely easy to create weird bugs.

Re: Go Concurrency vs. RxJS

#50
The JS examples don't seem too demonstrative to me. Especially for someone not very familiar with RxJS. Any time you're wrapping something with `from` or `of`, I raise an eyebrow

  export function pipeline(in$: Observable): 
  Observable {
      return in$.pipe(
          mergeMap(product => from(product.Images)),
      );
  }
Why use mergeMap at all here? Why not not just

  return in$.pipe(
    map(product => product.Images),
  );
I get that this is a toy example, not trying to be pedantic.
Post reply on HN