News for hackers. Stuff that matters.
Re:Lies we tell ourselves to keep using Golang by moralestapia on Friday April 29, 2022 @11:06AM (#31206106)
>read from multiple queues at the same time

That's a trivial thing in javascript.

Re:Lies we tell ourselves to keep using Golang by paskozdilar on Friday April 29, 2022 @11:21AM (#31206296)
If you could spare some time, would you please demonstrate an example?
Re:Lies we tell ourselves to keep using Golang by vbezhenar on Friday April 29, 2022 @12:07PM (#31206999)
You can use Promise.race to wait for the first resolved promise.
Re:Lies we tell ourselves to keep using Golang by moralestapia on Friday April 29, 2022 @11:31AM (#31206450)
Abusing notation a bit,

var a = new Queue();

var b = new Queue();

a.read(() => some callback);

b.read(() => some callback);

And code continues here without blocking.

To be honest, I think you could do the same in any (slightly) modern language.

Re:Lies we tell ourselves to keep using Golang by paskozdilar on Friday April 29, 2022 @02:45PM (#31209135)
Is the read() call running a task in the background? In that case, that's equivalent to launching two threads. For n queues, you'd need n tasks, and they'd hang in the background in case they never get a result and take up memory.
Re:Lies we tell ourselves to keep using Golang by metadat on Friday April 29, 2022 @11:14AM (#31206199)
How? Javascript is single threaded run loop.
Re:Lies we tell ourselves to keep using Golang by lalaithion on Friday April 29, 2022 @11:27AM (#31206373)
Re:Lies we tell ourselves to keep using Golang by metadat on Friday April 29, 2022 @11:47AM (#31206650)
>read from multiple queues at the same time

Agreed, and things happening "at the same time" are possible only with parallelism. Hence my question =)

Re:Lies we tell ourselves to keep using Golang by moralestapia on Friday April 29, 2022 @12:10PM (#31207034)
I interpreted "at the same time" as "without blocking",

But sure you could also add parallelism using a few built-in Node modules (there's cluster and worker threads, also don't know if atomics are already in Node, they are in V8),

It's not trivial anymore but also not that hard. A newcomer could figure it out in ~30 mins from the docs.

Re:Lies we tell ourselves to keep using Golang by metadat on Friday April 29, 2022 @12:25PM (#31207249)
Gotcha, sounds like we interpreted it differently. I appreciate you taking the time to clarify, I am an old hand as JS but didn't know true parallelism had become feasible these days. Thank you, sincerely!
Re:Lies we tell ourselves to keep using Golang by moralestapia on Friday April 29, 2022 @12:33PM (#31207350)
Don't worry, JS has come a long way.

During my PhD we had to crunch some numbers and my group usually makes use of C++ with libs for that. I tried doing it in Node using cluster and let it spread through our whole cluster of nodes (funny how it plays on words) and performance was worse obv. but not that bad, it was about 2x slower, but with that I was able to write code and test it in hours instead of days, and it didn't matter to me if a program that was going to take 2 hours was now taking 4 as I was going home anyway and check it out next morning ¯\_(ツ)_/¯. Plus, my experiment had a REST API for free (well, like 8 lines of code) and when I showed that to them they were :O.