TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Libraries can start processes too

70 点作者 sandbags将近 4 年前

5 条评论

jolux将近 4 年前
This is a huge part of the power of Elixir&#x2F;Erlang. Libraries can be written to use the same powers of isolation, resiliency, and concurrency that application code has, at no extra cost to the consumer and with total transparency.<p>You quickly realize that every function you call could be working asynchronously underneath, and it’s not scary because the whole system is designed to function like this.
dnautics将近 4 年前
I really wish that in elixir we drew a distinction between dependencies that do and don&#x27;t spawn their own supervision trees. It would be nice if this were reflected in, say, hex.pm, possibly using different tags for them.
评论 #28043523 未加载
评论 #28043019 未加载
评论 #28057885 未加载
dceddia将近 4 年前
In earlier versions of Elixir where you had to explicitly add the libraries as additional processes to start, I remember being very confused why things like e.g. an HTTP client needed its own process. To be honest I still felt a little uneasy about it every time. Thinking of those processes as just “the library needs some internal state” makes so much more sense!
评论 #28042913 未加载
AlchemistCamp将近 4 年前
Many, many libraries do this! It&#x27;s a key feature.<p>(to clarify, these are light-weight <i>Elixir</i> processes, not OS processes)
OskarS将近 4 年前
I think Erlang and Elixir are incredible, and this particular feature of libraries starting BEAM processes seems cool in the abstract. However, this PARTICULAR task, Erlang&#x2F;Elixir might be the worst possible language you could choose:<p>&gt; <i>The Elixir approach to shared mutable state is wrapping it in a process. In this case, I needed a counter and the easiest way to implement it is to use an Agent which is a kind of process designed to handle simple state. In this case, the get_and_update function allows me to return the counter and increment it as an atomic operation.</i><p>This is literally just an atomic counter. It’s a single CPU instruction that is guaranteed to be safe. I don’t care how lightweight a BEAM process is, it’s not faster than updating an atomic counter. Doing it this way is also absurdly more complicated than using, say, a std::atomic in C++ (or the equivalent type in other languages).<p>Again, I think Elixir is cool, but if you want to show off how cool it is, maybe don’t use an example that is incredibly much slower and more complicated than it should be. It’s not a great look for Elixir.
评论 #28043316 未加载
评论 #28043272 未加载
评论 #28047285 未加载