6 ms·
Unlike javascript, elixir makes you write synchronous code, e.g. def process_items(items) do items |> Task.async_stream(&Processor.process/
by out_of_protocol 3y ago
Unlike javascript, elixir makes you write synchronous code, e.g.
def process_items(items) do
items
|> Task.async_stream(&Processor.process/1, max_concurrency: 2, timeout: 7000, on_timeout: :kill_task)
|> Enum.to_list()
end
Semantics of regular and concurrent code is the same
- Dowwie 3y agocomment here is conveying that there is no function color, where a language distinguishes standard synchronous calls from asynchronous calls
- strzibny 3y agoThis. I don't want to be in an event loop by default.
- throwawaymaths 3y agoHate to break it to you but in the BEAM you're always in an event loop.
- ch4s3 3y agoNo really. The scheduler isn’t really like an event loop. The scheduler will only allow a task so many units of execution before pulling it off the processing queue and scheduling other work. You can block an event loop, but not the scheduler.
- toast0 3y agoAdding preemption doesn't make it not an event loop, IMHO.
- ch4s3 3y agoThe context of the discussion was the node event loop, which doesn’t have preemption. The BEAM scheduler is only like an event loop when you’re locked to one physical processor core, otherwise the schedule is spreading work across multiple OS level threads. You could squint and call this an event loop manager with preemption, but I think the phrase “event loop” detracts from the clarity of any correct description.
- gpderetta 3y agoAt the limit, there is always an event loop in the kernel. The question is how leaky are the abstractions on top.
- thibaut_barrere 3y agoVery convenient to parallelise HTTP queries (and without the need to go “evented”). One recent example where I assert that API responses match our OpenAPI specifications here, for the curious: https://github.com/etalab/transport-site/pull/3351/files#diff-e73c888e72cf3a5df29a7b628cb5ad208324e989ad8cc2cc5f7d12dce89a9707R38 https://github.com/etalab/transport-site/pull/3351/files#dif...
- jerf 3y agoNode has kind of wrecked the term "synchronous". It convinced many people that "synchronous" also entails "only thing running on the processor at the time" and "if you're 'synchronously' waiting on a file read the entire process is waiting". So when you say "Elixir/Erlang/any threaded language 'makes' you write synchronous code", to the people who most need to hear this, those steeped in the async way of the world, you confuse them because to them that means your language can only do one thing at a time. I'm not saying I'm happy about this or that the meaning has "really" changed; I'm just saying from experience you don't really want to phrase it this way because you only reach those who already know.
- lionkor 3y agoThats so sad, because any truly parallel workload runs synchronously, on multiple processors, not asynchronously (i.e. on as little as a single processor)
- cultofmetatron 3y agoyou can replicate this using primises source: nodejs dev for 8 years, now fulltime elixir dev for the last 5