3 -й протокол, который мы не можем изменить. Стоимость изменения в данный момент. < /P>
Код: Выделить всё
public protocol SyncRunner {
associatedtype R
func run() -> Result
}
< /code>
И это синхронизация реализации примера Actor. < /p>
final actor CounterSyncRunner: SyncRunner {
private let queue = DispatchSerialQueue(label: "useCaseQueue", qos: .utility)
nonisolated var unownedExecutor: UnownedSerialExecutor {
queue.asUnownedSerialExecutor()
}
private var counter: Int = 0
nonisolated func run() -> Result {
// I would like to call it in the context of actor but in a synchronous /blocking manner. Is this good way to do it?
var result: Int = 0
queue.sync { // sync here
assumeIsolated {
$0.counter += 1
result = $0.counter
}
}
return .success(result)
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... synchronio
Мобильная версия