607
Hexed by async (fed.dyne.org)
top 25 comments
sorted by: hot top controversial new old
[-] osef897@lemmy.world 50 points 3 weeks ago

Promise.resolve('haha, good one');

[-] naught@sh.itjust.works 19 points 3 weeks ago

asyncio.run(easy_peasy())

[-] pimeys@lemmy.nauk.io 45 points 3 weeks ago

That's why you write your protocol as a sync library, then implement the async IO separately and mapping the data over the protocol modules.

[-] shikogo@pawb.social 36 points 3 weeks ago

I... Don't know what this means

[-] pimeys@lemmy.nauk.io 43 points 3 weeks ago

So basically your typical network protocol is something that converts an async stream of bytes into things like Postgres Row objects. What you do then is you write a synchronous library that does the byte conversion, then you write an asynchronous library that talks with the database with async functions, but most of the business logic is sync for converting the data coming from the async pipe.

Now, this can also be done in a higher level application. You do a server that is by nature async in 2024. Write the server part in async, and implement a sync set of mapping functions which take a request coming in and returns a response. This can be sync. If you need a database, this sync set of functions maps a request to a database query, and your async code can then call the database with the query. Another set of sync functions maps the database result into http response. No need to color everything async.

The good part with this approach is that if you want to make a completely sync version of this library or application, you just rewrite the async IO parts and can reuse all the protocol business logic. And you can provide sync and async versions of your library too!

[-] azimir@lemmy.ml 10 points 3 weeks ago

This approach is so much nicer than the threading/queuing approaches we used to have. One async showed up, a ton of the work go pulled out of protocol handing and distributed subsystem sync efforts.

Long lived the multi threaded C++ server buffer! Today, async beging to rule the roost.

[-] pimeys@lemmy.nauk.io 4 points 3 weeks ago

It kind of fails with certain protocols. I once wrote an async MSSQL client for Rust, and some data doesn't say its size in the headers. So this kind of forced the business logic to be async too.

[-] azimir@lemmy.ml 3 points 3 weeks ago

Yeah, those durn data size fields. At first you're like "why would you do this? It's specified in the spec, right?" Then you start consuming the data stream and go "oh, yeah need this".

I was doing some driver work for a real time location tracking board. The serial stream protocol was very well documented and designed. Plenty of byte length count fields, though.

[-] jaybone@lemmy.world 10 points 3 weeks ago

What is computer science degree?

[-] pimeys@lemmy.nauk.io 13 points 3 weeks ago

Never had one, just partied in the uni and dropped out :D

[-] jaybone@lemmy.world 6 points 3 weeks ago
[-] bitfucker@programming.dev 6 points 3 weeks ago

Long live sans io!

[-] astrsk@fedia.io 6 points 3 weeks ago

Or just make a bunch of static helpers >:)

[-] Thcdenton@lemmy.world 9 points 3 weeks ago

I heard the pop in my head

[-] muntedcrocodile@lemm.ee 7 points 3 weeks ago

I hate asyncs, but I don't mind the way Python does it.

[-] grandma@sh.itjust.works 9 points 3 weeks ago

I hate python async with a burning passion but I'll admit most of it is a consequence of skill issues

[-] muntedcrocodile@lemm.ee 1 points 3 weeks ago* (last edited 3 weeks ago)

What do u hate about it so much? I find it a very intuitive way to do async. Especially with asynchronous loops.

[-] psivchaz@reddthat.com 9 points 3 weeks ago

I like async but dislike await. I spend entirely too much time on everything I build trying to maximize how much I can do in parallel because I find it tremendously satisfying.

[-] Vent@lemm.ee 4 points 3 weeks ago

You probably already know this, or are talking about another language, but JavaScript is inherently single threaded, so unless you're running blocking I/O in parallel, you won't actually see any performance boost. Service workers get their own thread though.

[-] Luvon@beehaw.org 4 points 3 weeks ago

Await is usually there either because the performance doesn’t matter and the legibility is much higher with it, and/or because there are a series of asynchronous actions that depend on each other and await lets you write them as if they are sync because related to each other they are.

[-] bitfucker@programming.dev 1 points 3 weeks ago

Then Promise.all is for you!

[-] entropicdrift@lemmy.sdf.org 1 points 3 weeks ago

TaskGroup in Python is great

[-] GissaMittJobb@lemmy.ml 3 points 3 weeks ago* (last edited 3 weeks ago)

Kotlin-style async is pretty neat, ngl.

I know about overhead and fairness guarantees and context switching impact, but for simplicity's sake I just generally start new threads in Rust. Introducing async isn't that much harder, but for what I write it's generally fine.

Java's project Loom looks pretty cool, though I've read scheduling remains challenging and several libraries seem to have the occasional deadlocking issues.

[-] No_Support_8363@lemm.ee 1 points 2 weeks ago
this post was submitted on 24 Aug 2024
607 points (99.2% liked)

Programmer Humor

32024 readers
553 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS