Skip to content

Commit

Permalink
API & Swift version updates
Browse files Browse the repository at this point in the history
    - Global disposable stages are now reset via Disposables.stage
    - Builder methods moved to Disposables
    - AnyDisposable -> AutoDisposable
      - .erase() -> .auto()
      - AutoDisposables can now *lose* their ownership via `take()`
      - They can be tested for ownership with `.hasOwnership`
      - DisposableStages take ownership from AutoDisposables maintaining
        previous behavior.
    - ErasedDisposable introduced and does not have ownership / auto-dispose.
      - created via .erased()
  • Loading branch information
adam-zethraeus committed Apr 5, 2023
1 parent daa383e commit 2b6db4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 0 additions & 5 deletions Sources/Disposable/Disposable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ extension Disposable where Self == AutoDisposable {
public func erased() -> ErasedDisposable {
ErasedDisposable(self)
}

public func take() -> ErasedDisposable {
take()
return ErasedDisposable(self)
}
}

extension Disposable where Self == ErasedDisposable {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Disposable/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Disposables {
mode: Mode,
priority: TaskPriority? = nil,
action: @escaping @Sendable () async -> Success,
onDispose: @escaping @Sendable () -> Void
onDispose: @escaping @Sendable () -> Void = { }
) where Failure == Never {
let disposable = ErasedDisposable(disposal: onDispose)
self.disposable = disposable
Expand All @@ -43,7 +43,7 @@ extension Disposables {
mode: Mode,
priority: TaskPriority? = nil,
action: @escaping @Sendable () async throws -> Success,
onDispose: @escaping @Sendable () -> Void
onDispose: @escaping @Sendable () -> Void = { }
) where Failure == any Error {
let action = {
try SwiftTask.checkCancellation()
Expand Down Expand Up @@ -110,7 +110,7 @@ extension Disposables {
public static func attached(
priority: TaskPriority? = nil,
action: @escaping @Sendable () async -> Success,
onDispose: @escaping @Sendable () -> Void
onDispose: @escaping @Sendable () -> Void = { }
) -> Task<Success, Failure> where Failure == Never {
.init(mode: .attached, priority: priority, action: action, onDispose: onDispose)
}
Expand All @@ -127,7 +127,7 @@ extension Disposables {
public static func attached(
priority: TaskPriority? = nil,
action: @escaping @Sendable () async throws -> Success,
onDispose: @escaping @Sendable () -> Void
onDispose: @escaping @Sendable () -> Void = { }
) -> Task<Success, Failure> where Failure == any Error {
.init(mode: .attached, priority: priority, action: action, onDispose: onDispose)
}
Expand All @@ -145,7 +145,7 @@ extension Disposables {
public static func detached(
priority: TaskPriority? = nil,
action: @escaping @Sendable () async -> Success,
onDispose: @escaping @Sendable () -> Void
onDispose: @escaping @Sendable () -> Void = { }
) -> Task<Success, Failure> where Failure == Never {
.init(mode: .detached, priority: priority, action: action, onDispose: onDispose)
}
Expand All @@ -164,7 +164,7 @@ extension Disposables {
public static func detached(
priority: TaskPriority? = nil,
action: @escaping @Sendable () async throws -> Success,
onDispose: @escaping @Sendable () -> Void
onDispose: @escaping @Sendable () -> Void = { }
) -> Task<Success, Failure> where Failure == any Error {
.init(mode: .detached, priority: priority, action: action, onDispose: onDispose)
}
Expand Down

0 comments on commit 2b6db4e

Please sign in to comment.