apple / swift-distributed-actors

Peer-to-peer cluster implementation for Swift Distributed Actors
https://apple.github.io/swift-distributed-actors/
Apache License 2.0
598 stars 57 forks source link

Enforced Codable Messages: Guidance what to do about "only local message" carrying functions #609

Closed ktoso closed 3 years ago

ktoso commented 4 years ago

Actorable's today can't survive this.

I'm implementing CASPaxos for fun, and the submitting of a change is done via sending a pure function to perform the change.

The actorable would have something like:

    public func change(key: String, update: @escaping (Value) throws -> Value, extra: Extras) -> EventLoopFuture<Value>

of course, that update closure can never be sent across the wire, and we "know that", we only ever send it locally. As all messages are required to be codable now though... we can't do this anymore, since -> should never be codable.


Options...

ktoso commented 4 years ago

The workaround:

    typealias ChangeFunc = ChangeFunction<Value>
    struct ChangeFunction<Value>: NonTransportableActorMessage {
        let change: (Value) throws -> Value
    }
public func change(key: String, update: ChangeFunc, extra: Extras) -> EventLoopFuture<Value>

I guess that's fine; perhaps worth documenting as a pattern

ktoso commented 3 years ago

This is solved in the language with the introduction of whenLocal on distributed actors.