mirror of
https://github.com/samsonjs/NotificationTask.git
synced 2026-03-29 09:55:51 +00:00
Compare commits
No commits in common. "main" and "0.1.1" have entirely different histories.
2 changed files with 4 additions and 23 deletions
|
|
@ -1,7 +1,3 @@
|
||||||
**Obsoleted by [AsyncMonitor](https://github.com/samsonjs/AsyncMonitor) and no longer maintained**
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
# NotificationTask
|
# NotificationTask
|
||||||
|
|
||||||
[](https://0dependencies.dev)
|
[](https://0dependencies.dev)
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ extension Notification: @unchecked @retroactive Sendable {}
|
||||||
/// always receives a strong reference. This one is called ``init(name:context:center:performing:)``.
|
/// 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
|
/// ``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: Hashable {
|
@MainActor public final class NotificationTask {
|
||||||
let task: Task<Void, Never>
|
var task: Task<Void, Never>?
|
||||||
|
|
||||||
init(task: Task<Void, Never>) {
|
init(task: Task<Void, Never>) {
|
||||||
self.task = task
|
self.task = task
|
||||||
|
|
@ -49,22 +49,7 @@ extension Notification: @unchecked @retroactive Sendable {}
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
task.cancel()
|
task?.cancel()
|
||||||
}
|
task = nil
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue