HomeiOS Developmentios - Implementing Mix map operator that learn information from MainActor

ios – Implementing Mix map operator that learn information from MainActor


I’ve a sense that Swift Concurrency is preventing agains me on a regular basis. It’s actually irritating.

My drawback. I must create Mix writer to emit battery state on iOS machine.

Thus far I’ve this:


extension Notification.Title {
    var writer: NotificationCenter.Writer {
        return NotificationCenter.default.writer(for: self)
    }
}
func createDefaultPublisher() -> AnyPublisher {
    UIDevice.batteryLevelDidChangeNotification
        .writer
        .compactMap { $0.object as? UIDevice }
        .map { machine in
            Future { promise in
                Activity { @MainActor in
                    promise(.success(machine.batteryLevel)) // Sending 'promise' dangers inflicting information races
                }
            }
        }
        .switchToLatest()
        .eraseToAnyPublisher()
}

So the tough half for me is find out how to implement map operator. I want to change to the MainActor there so I am utilizing Future with promise callback. The issue right here is: Sending ‘promise’ dangers inflicting information races. So I questioning find out how to do it correctly in Swift 6 in challenge configured with Full Strict Concurrency Checking

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments