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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Portable and Interoperable Async Rust

97 点作者 bmcniel超过 3 年前

7 条评论

zackmorris超过 3 年前
This is good info, and will be very useful for people porting code from other languages like Javascript. But I&#x27;m still in mourning that async took over the world.<p>I grew up with cooperative multitasking on Mac OS and used Apple&#x27;s OpenTransport heavily in the mid-90s before Mac OS X provided sockets. Then I spent several years working on various nonblocking networking approaches like coroutines for games before the web figured out async. I went about as far down the nonblocking IO rabbit hole as anyone would dare.<p>But there&#x27;s no there there. After I learned Unix sockets (everything is a stream, even files) it took me to a different level of abstraction where now I literally don&#x27;t even think about async. I put it in the same mental bin as mutexes, locking IO, busy waiting, polling, even mutability. That&#x27;s because no matter how it&#x27;s structured, async code can never get away from the fact that it&#x27;s a monad. The thing it&#x27;s returning changes value at some point in the future, which can quickly lead to nondeterministic behavior without constant vigilance. Now maybe my terminology here is not quite right, but this concept is critical to grasp, or else determinism will be difficult to achieve.<p>I think a far better programming pattern is the Actor model, which is basically the Unix model and piping immutable data around. This is more similar to how Go and Erlang work, although I&#x27;m disappointed in pretty much all languages for not enforcing process separation strongly enough.<p>Until someone really understands everything I just said, I would be very wary of using async and would only use it for porting purposes, never for new development. I feel rather strongly that async is something that we&#x27;ll be dealing with and cleaning up after for the next couple of decades, at least.
评论 #29488622 未加载
评论 #29487127 未加载
Zababa超过 3 年前
OCaml is currently going through something similar, with some solutions in sight. The &quot;motivation&quot; part of the eio (<a href="https:&#x2F;&#x2F;github.com&#x2F;ocaml-multicore&#x2F;eio" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ocaml-multicore&#x2F;eio</a>) documentation is a great introduction:<p>&quot;The Unix library provided with OCaml uses blocking IO operations, and is not well suited to concurrent programs such as network services or interactive applications. For many years, the solution to this has been libraries such as Lwt and Async, which provide a monadic interface. These libraries allow writing code as if there were multiple threads of execution, each with their own stack, but the stacks are simulated using the heap.<p>The multicore version of OCaml adds support for &quot;effects&quot;, removing the need for monadic code here. Using effects brings several advantages:<p>1. It&#x27;s faster, because no heap allocations are needed to simulate a stack.<p>2. Concurrent code can be written in the same style as plain non-concurrent code.<p>3. Because a real stack is used, backtraces from exceptions work as expected.<p>4. Other features of the language (such as try ... with ...) can be used in concurrent code.<p>Additionally, modern operating systems provide high-performance alternatives to the old Unix select call. For example, Linux&#x27;s io-uring system has applications write the operations they want to perform to a ring buffer, which Linux handles asynchronously.&quot;
评论 #29482858 未加载
bishop_mandible超过 3 年前
&quot;Wenn man nicht mehr weiter weiß, gründet man einen Arbeitskreis.&quot; - Ancient German proverb. (Translation: &quot;If you don&#x27;t know what to do next, you set up a working group&quot;)
评论 #29484726 未加载
crtc超过 3 年前
On a somewhat unrelated note: What consequences did the Rust mod team resignation lead to? The last thing I heard was the blog post: <a href="https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;inside-rust&#x2F;2021&#x2F;11&#x2F;25&#x2F;in-response-to-the-moderation-team-resignation.html" rel="nofollow">https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;inside-rust&#x2F;2021&#x2F;11&#x2F;25&#x2F;in-respons...</a><p>But I haven&#x27;t seen any public discussions on the future of Rust governance, how to make the core team accountable, or other consequences since.
评论 #29484122 未加载
评论 #29483160 未加载
评论 #29483089 未加载
ezekiel68超过 3 年前
I take the opposite tack. Who, precisely is clamoring for this? Why not &quot;let 100 flowers grow&quot; (present condition) and allow the various solutions to mature to the point that a de facto standard emerges? The claim is made: &quot;choosing a runtime locks you into a subset of the ecosystem,&quot; to which I answer, &quot;So, what?&quot; If I want to log my server events or take advantage of a protocol encoding method or compress my data -- all of these and every other &quot;big&quot; choice I make locks me into a similar library ecosystem niche. I despise this &quot;everything&#x27;s amazing and nobody&#x27;s happy&quot; vibe. The async library authors have plenty on their plates without some sub-committee crashing in and dictating their features and release schedules.<p>By the way, using Go as an example is a joke since -- from the early Go bootcamp I attended in 2014, the best practice has been to use a 3rd-party http router (these days: gorilla? httprouter? chi? etc) instead of the one provided in the standard library. Instead of being _told_ what to use, let&#x27;s get back to being interested enough that we read the docs, take in the reviews &amp; benchmarks, and decide for ourselves.
评论 #29484512 未加载
评论 #29484259 未加载
评论 #29487499 未加载
pie_flavor超过 3 年前
A &#x27;toy&#x27; executor is worthless for those who need to program in async and worthless for those who don&#x27;t. Toy functionality has always been, and should continue to be, supplied by libraries.
camdenlock超过 3 年前
Why has Rust struggled so much with this, where Go has succeeded from the start with its language-level “goroutine” concept and runtime? Maybe it just wasn’t a focal area for the original Rust designers?
评论 #29483147 未加载
评论 #29483064 未加载
评论 #29482467 未加载
评论 #29482285 未加载
评论 #29482207 未加载
评论 #29484129 未加载
评论 #29484325 未加载
评论 #29483751 未加载
评论 #29482185 未加载
评论 #29526658 未加载
评论 #29489194 未加载
评论 #29483888 未加载
评论 #29482623 未加载