MainOffender
MainOffender copied to clipboard
Utilities for transitioning to Swift Concurrency
MainOffender
A tiny package with utilities to help with Swift Concurrency
You can also just copy-paste the stuff you need into your project if you aren't into taking on the dependency. I won't be offended (ha!).
Features:
-
DispatchQueue.mainActor
for aDispatchQueue
proxy that is@MainActor
-compatible -
OperationQueue.mainActor
for anOperationQueue
proxy that is@MainActor
-compatible -
UnsafeBlockOperation
forBlockOperation
withoutSendable
checking - Additions to
OperationQueue
to submit blocks directly withoutSendable
checking -
addUnsafeObserver(forName:object:queue:using:)
forNotificationCenter
Usage
OperationQueue
did not (yet?) get the same unsafe features of DispatchQueue
. Here are some unsafe variants that allow you to make use of OperationQueue
without warnings.
let op = UnsafeBlockOperation {
// non-Sendable captures ok
}
operationQueue.addOperation(op)
queue.addUnsafeOperation {
// non-Sendable captures ok
}
queue.addUnsafeBarrierBlock {
// non-Sendable captures ok
}
Installation
dependencies: [
.package(url: "https://github.com/mattmassicotte/MainOffender", from: "0.1.0")
]
Contributing and Collaboration
I'd love to hear from you! Get in touch via mastodon, an issue, or a pull request.
I prefer collaboration, and would love to find ways to work together if you have a similar project.
I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.
By participating in this project you agree to abide by the Contributor Code of Conduct.