Add actor model
RoyalIcing opened this issue · comments
See GenServer from Elixir
protocol Actor {
associatedtype MessageIn
associatedtype MessageOut
func handle(message: MessageIn) -> Deferred<MessageOut>
}
struct ActorID : Hashable {
var identifier: String
}
class Supervisor {
func start<A: Actor>(actor: A, identifier: String) -> Deffered<ActorID>
func find<A: Actor>(id: ActorID) -> Deferred<A>
func stop(id: ActorID) -> Deferred<()>
func message<A: ActorID>(id: ActorID, message: A.MessageIn) -> Deferred<A.MessageOut>
}
struct Cache : Actor {
enum MessageIn {
case setKey(key: String, value: Data, expires: Date?)
case setKeyPath(keyPath: [String], value: String, expires: Date?)
case getKey(key: String)
case getKeyPath(keyPath: [String])
case fetchKey(key: String)
}
enum MessageOut {
case ok
case value(value: Data?)
}
enum Error {
case keyPathNotFound(keyPath: [String])
}
private var values: [String: Data]
func handle(message: MessageIn) -> Deferred<MessageOut> {
…
}
}