←back to thread

A Few Words About Async

(yoric.github.io)
82 points vinhnx | 1 comments | | HN request time: 0s | source
Show context
travisgriggs ◴[] No.45788011[source]
That was “quite a few” words. I wish the author had taken more time with Elixir/Erlang.

Languages like rust/python that use lots of reserved keywords, especially for control flow seem to have reached for that arrow to solve the “event loop” problem as described.

In BEAM languages, that very event loop stays front and center, you don’t have this awkward entanglement between reserved keywords and event loop. If you want another chunk of thing to happen later because of an event, you just arrange for an event of that nature to be delivered. No callbacks. No async coloring. Just events. The solution to the event problem is to double down and make your event loop more generally usable.

replies(1): >>45790783 #
evnc ◴[] No.45790783[source]
Interesting. Does that mean if you want to say, make an asynchronous http request, you do something like “fire_event(HttpRequestEvent(…))” which returns immediately, and somewhere else define a handler like “on_event(HttpResponseEvent, function (event) { … })” ? So you kind of have to manually break your function up into a state machine composed of event handlers? How do you associate a given HttpResponseEvent with a specific HttpRequestEvent?
replies(2): >>45791510 #>>45791564 #
1. travisgriggs ◴[] No.45791564[source]
Elixir IS very state machine like.

So yes, your event loop processes the results of asynchronous work launched because of earlier events the same way.

Part of what makes this work, is the awesome function clause matching. Coordinating origin of async work and result of async work is really easy because you can match on any form of terms your heart desires, and everything is always immutable.