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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Concurrency in Swift: One possible approach

188 点作者 spearo77将近 8 年前

14 条评论

lobster_johnson将近 8 年前
I&#x27;m surprised that async&#x2F;await is the preferred idiom.<p>Having worked with async&#x2F;await in Node.js a lot, it is of course a significantly better solution than plain promises, but it is also quite invasive; in my experience, <i>most</i> async code is invoked with &quot;await&quot;. It&#x27;s rare to actually need to handle it as a promise; the two main use cases where you want to handle the promise as a promise is either when doing something like a parallel map, or when you need to deal with old callback-style code where an explicit promise needs to be created because the resolve&#x2F;reject functions must be invoked as a result of an event or callback.<p>Would it not be better to invert this -- which is the route Erlang and Go went -- and make it explicit when you&#x27;re spawning something async where you don&#x27;t want to deal with the result right away? In Go, you just use the &quot;go&quot; keyword to make something async. So the caller decides what&#x27;s async, not the callee. If callers arbitrarily decide whether to be async or not, a single async call ends up infecting the whole call chain (which need to be marked &quot;async&quot; unless you&#x27;re explicitly handling the promise&#x2F;continuation without &quot;await&quot;).
评论 #15042683 未加载
评论 #15045048 未加载
评论 #15042647 未加载
liuliu将近 8 年前
Async &#x2F; await also need a idiom to accompany on how to support cancellation. In practice, cancellation happens a lot because the unbounded latency for async operations. Without a throughout support, async &#x2F; await syntax is probably usable on server side somewhat but still hardly applicable on client side (as the latency is unbounded). On the other hand, C# does go through the pain and added cancellation support to all its standard libraries async API.
评论 #15044339 未加载
评论 #15045331 未加载
jzelinskie将近 8 年前
As someone who doesn&#x27;t develop for the Apple ecosystem, I can&#x27;t quite find one place that articulates well what the Swift development philosophy is and what it brings to the table besides just being modern language with shims for interacting with legacy Apple APIs. Why would I use Swift on Linux?<p>Most of the posts that I see related to Swift are RFCs evaluating solutions to problems in other languages. I rarely get to see the actual solutions being integrated into the language. Is this just a result of HN readers caring more about language design than learning to leverage the Swift language?
评论 #15044433 未加载
评论 #15042806 未加载
评论 #15042697 未加载
评论 #15042661 未加载
haimez将近 8 年前
Feels like the elephant in the room for the description is not once mentioning Futures but instead jumping straight to using async &#x2F; await keywords and the actor model.<p>As evidenced by C#, you can&#x27;t avoid leaking the type signature of async operations if you actually support generic programming- so while that&#x27;s a nice ergonomics improvement, it only adds complexity to the actual concurrency model. Go enthusiasts out there will appreciate that go solves this by refusing to support PROGRAMMABLE generic abstractions at all (looking at you, channels and map).<p>Referencing the actor model and making it first class is interesting, but probably a mistake. Actors are hard to reason about because they&#x27;re so flexible. Pony is a good recent attempt at combining static types with actors, bit they didn&#x27;t put performance into the &quot;non-goals&quot; section of their language spec.<p>If you want task level concurrency and you want it to play nice with your type system, you have to start with Scala and work backward to the alternative implementation choices you&#x27;re going to make because it checks all the boxes of all the &quot;goals&quot; and ALSO has a very mature actor model implementation that doesn&#x27;t require promoting actors to keyword status in the language.
评论 #15042644 未加载
评论 #15042788 未加载
spearo77将近 8 年前
And the supporting swift Pull Request is <a href="https:&#x2F;&#x2F;github.com&#x2F;apple&#x2F;swift&#x2F;pull&#x2F;11501" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;apple&#x2F;swift&#x2F;pull&#x2F;11501</a>
zzzcpan将近 8 年前
Maybe it&#x27;s time for Swift to decide whether it&#x27;s going to stick to multicore systems or actually leave this single box mindset and enable distributed systems programming. I think designing for distributed systems first could lead to a lot of right choices from the beginning and would still allow for various optimizations later to get the best performance from multicore. Alternative is not very promising and provides a lot of room for really stupid mistakes. Either way, I&#x27;m glad to see actor model getting more traction.
评论 #15043466 未加载
panic将近 8 年前
Definitely some cool ideas here! The motivation seems a little high-level to me, though. Language features ought to help you solve concrete, real-world problems. I can understand what problem async&#x2F;await solves -- there&#x27;s a great example with code -- but the actor stuff isn&#x27;t as clear-cut.
lngnmn将近 8 年前
Software interrupts is the right answer to concurrency nonsensical hype. Sometimes old is gold.<p>Wrapping specialized interrupt handlers into some higher lebel API, such as AIO, is the right way.<p>Async&#x2F;await is a mess. Concurrency cannot be generalized to cover all the possible cases. It must have specialization.<p>Engineers of old times who created the early classic OSes were bright people, contrary to current hipsters.<p>Once popularized, flawed abstractions and apis such as pthreads would stick (only idiots would accept shared stack and signals).<p>Look at how an OS implements concurrency and wrap it into higher level API. That&#x27;s it.
评论 #15046717 未加载
weitzj超过 7 年前
Related Tweet from Joe Armstrong: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;joeerl&#x2F;status&#x2F;898444575668404224" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;joeerl&#x2F;status&#x2F;898444575668404224</a>
hellofunk将近 8 年前
&gt; the speed of light and wire delay become an inherently limiting factor for very large shared memory systems<p>Wow, cool to see actual speed of light mentioned as a factor, never seen that before.
评论 #15043542 未加载
jorblumesea将近 8 年前
Doesn&#x27;t Chris work at Google now? Where does he find the time to just go off and implement the Actor Model? I assume this was done when he was still at Apple?
评论 #15043279 未加载
评论 #15042679 未加载
评论 #15042964 未加载
评论 #15042682 未加载
tambourine_man将近 8 年前
Must be crazy for Apple to have such an influencing voice on Swift and LLVM working for its archenemy
评论 #15042687 未加载
评论 #15042601 未加载
perfectstorm将近 8 年前
correct me if I&#x27;m wrong but this is what C# has? I recall writing async and await when I did a Windows Phone app many years ago.
评论 #15042065 未加载
0xbear将近 8 年前
Any such model MUST show what error handling will look like. Otherwise you end up with &quot;log to console and ignore&quot; approach so prevalent in Android SDK examples, which people _will_ copy unchanged.
评论 #15042247 未加载
评论 #15042680 未加载