Compare commits

...

2 commits
0.1.1 ... main

Author SHA1 Message Date
1cd6dba627
Update Readme.md 2025-04-26 18:07:52 -07:00
638c5942c0
Add Hashable conformance 2025-04-19 13:25:59 -07:00
2 changed files with 23 additions and 4 deletions

View file

@ -1,3 +1,7 @@
**Obsoleted by [AsyncMonitor](https://github.com/samsonjs/AsyncMonitor) and no longer maintained**
----
# NotificationTask
[![0 dependencies!](https://0dependencies.dev/0dependencies.svg)](https://0dependencies.dev)

View file

@ -14,8 +14,8 @@ extension Notification: @unchecked @retroactive Sendable {}
/// always receives a strong reference. This one is called ``init(name:context:center:performing:)``.
///
/// ``NotificationTask`` is bound to the main actor and is intended to be used in your view layer. This keeps it simple
@MainActor public final class NotificationTask {
var task: Task<Void, Never>?
@MainActor public final class NotificationTask: Hashable {
let task: Task<Void, Never>
init(task: Task<Void, Never>) {
self.task = task
@ -49,7 +49,22 @@ extension Notification: @unchecked @retroactive Sendable {}
}
deinit {
task?.cancel()
task = nil
task.cancel()
}
public func store(in set: inout Set<NotificationTask>) {
set.insert(self)
}
}
// MARK: - Hashable conformance
public extension NotificationTask {
nonisolated static func == (lhs: NotificationTask, rhs: NotificationTask) -> Bool {
ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
}
nonisolated func hash(into hasher: inout Hasher) {
hasher.combine(task)
}
}