2 ms·
FTA: ”This is a common pattern: a class with a private queue and some properties that should only be accessed on the queue. We replace this manual queue managem
by Someone 6y ago
FTA: ”This is a common pattern: a class with a private queue and some properties that should only be accessed on the queue. We replace this manual queue management with an actor class
[…]
Things to note about this example:
- Declaring a class to be an actor is similar to giving a class a private queue and synchronizing all access to its private state through that queue.
- Because this synchronization is now understood by the compiler, you cannot forget to use the queue to protect state: the compiler will ensure that you are running on the queue in the class's methods, and it will prevent you from accessing the state outside those methods.
- Because the compiler is responsible for doing this, it can be smarter about optimizing away synchronization, like when a method starts by calling an async function on a different actor.”
The article also links to
- https://forums.swift.org/t/concurrency-actors-actor-isolation/41613 https://forums.swift.org/t/concurrency-actors-actor-isolatio... (pitch for implementing actors)
- https://github.com/DougGregor/swift-evolution/blob/actors/proposals/nnnn-actors.md https://github.com/DougGregor/swift-evolution/blob/actors/pr..., which links to https://github.com/DougGregor/swift-evolution/blob/actors/proposals/nnnn-actors.md https://github.com/DougGregor/swift-evolution/blob/actors/pr... (proposal for implementing actors)
I don’t know Erlang well, but what’s missing?
- dnautics 6y agoMonitors, linking, supervision trees, vm-level introspection into the state of the actors, distribution primitives that make actor identity nonlocal across clusters, actor cancellation (like kill -KILL), graceful actor shutdown, sane id serialization (how easy is it for me to serialize an actor Id, put it on a kafka queue and have it come back in a response so I can route the response back to the actor) etc, etc, etc.
- dnautics 6y agoadditionally if you go to Elixir, they've implemented async/await on top of the not-really-"actors" of the erlang VM in its standard library, and it's super easy to use and understand. Arguably easier than async/yield/await like exists in most languages that use async as a coroutine serialization primitive.