From a4348e7c8b5e10bd8bc13ef880acd640a9c83104 Mon Sep 17 00:00:00 2001 From: adamz Date: Mon, 3 Jul 2023 02:32:09 -0700 Subject: [PATCH] update documentation and swift version syntax --- Package.swift | 20 ++++++++++++++++++- .../Bridging/CombineExtensions.swift | 16 ++++++++++++++- Sources/Disposable/ConvenienceStages.swift | 4 ++-- Sources/Disposable/Disposable.swift | 4 ++-- Sources/Disposable/DisposableBuilder.swift | 14 ------------- Sources/Disposable/Locked.swift | 20 +++++++++---------- Sources/Disposable/Task.swift | 4 ++-- 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/Package.swift b/Package.swift index 7bc0de0..f81fad3 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,9 @@ let package = Package( ], targets: [ .target( - name: "Disposable" + name: "Disposable", + dependencies: [], + swiftSettings: Env.swiftSettings ), .testTarget( name: "DisposableTests", @@ -31,3 +33,19 @@ let package = Package( ), ] ) + +// MARK: - Env + +private enum Env { + static let swiftSettings: [SwiftSetting] = { + var settings: [SwiftSetting] = [] + settings.append(contentsOf: [ + .enableUpcomingFeature("ConciseMagicFile"), + .enableUpcomingFeature("ExistentialAny"), + .enableUpcomingFeature("StrictConcurrency"), + .enableUpcomingFeature("ImplicitOpenExistentials"), + .enableUpcomingFeature("BareSlashRegexLiterals"), + ]) + return settings + }() +} diff --git a/Sources/Disposable/Bridging/CombineExtensions.swift b/Sources/Disposable/Bridging/CombineExtensions.swift index b303f50..f1e52b8 100644 --- a/Sources/Disposable/Bridging/CombineExtensions.swift +++ b/Sources/Disposable/Bridging/CombineExtensions.swift @@ -2,11 +2,25 @@ import Combine extension ErasedDisposable { - public init(_ cancellable: Cancellable) { + public init(_ cancellable: some Combine.Cancellable) { self.init { cancellable.cancel() } } } +extension DisposableBuilder { + public static func buildExpression( + _ cancellable: some Combine + .Cancellable + ) -> [ErasedDisposable] { + [ErasedDisposable(cancellable)] + } + + public static func buildExpression(_ cancellables: [any Combine.Cancellable]) + -> [ErasedDisposable] + { + cancellables.map { ErasedDisposable($0) } + } +} #endif diff --git a/Sources/Disposable/ConvenienceStages.swift b/Sources/Disposable/ConvenienceStages.swift index 401c44e..4e89cae 100644 --- a/Sources/Disposable/ConvenienceStages.swift +++ b/Sources/Disposable/ConvenienceStages.swift @@ -62,8 +62,8 @@ extension Disposables.stages { // MARK: Fileprivate fileprivate static let indefinite = DisposableStage() - fileprivate static var identifiedStage = Locked([String: Disposable]()) - fileprivate static var callSiteStage = Locked([String: Disposable]()) + fileprivate static var identifiedStage = Locked([String: any Disposable]()) + fileprivate static var callSiteStage = Locked([String: any Disposable]()) } diff --git a/Sources/Disposable/Disposable.swift b/Sources/Disposable/Disposable.swift index 9b1fc06..fe8c5cb 100644 --- a/Sources/Disposable/Disposable.swift +++ b/Sources/Disposable/Disposable.swift @@ -4,8 +4,8 @@ /// Disposables should stop any remaining work as quickly as possible /// when ``dispose()`` is called. /// -/// A disposable can be type-erased to ``AnyDisposable`` via ``dispose()``. -/// Disposal is automatically triggered on an ``AnyDisposable`` once it has no +/// A disposable can be type-erased to ``AutoDisposable`` via ``dispose()``. +/// Disposal is automatically triggered on an ``AutoDisposable`` once it has no /// remaining inbound references to it. /// /// Disposables can be grouped together and stored with a ``DisposableStage``. diff --git a/Sources/Disposable/DisposableBuilder.swift b/Sources/Disposable/DisposableBuilder.swift index 02e27f0..aa188b6 100644 --- a/Sources/Disposable/DisposableBuilder.swift +++ b/Sources/Disposable/DisposableBuilder.swift @@ -1,7 +1,3 @@ -#if canImport(Combine) -import Combine -#endif - // MARK: - DisposableBuilder @resultBuilder @@ -10,16 +6,6 @@ public enum DisposableBuilder { [ErasedDisposable(disposable)] } - #if canImport(Combine) - public static func buildExpression(_ cancellable: some Cancellable) -> [ErasedDisposable] { - [ErasedDisposable(cancellable)] - } - - public static func buildExpression(_ cancellables: [any Cancellable]) -> [ErasedDisposable] { - cancellables.map { ErasedDisposable($0) } - } - #endif - public static func buildExpression(_: ()) -> [ErasedDisposable] { [] } diff --git a/Sources/Disposable/Locked.swift b/Sources/Disposable/Locked.swift index e3e2d42..9e758a4 100644 --- a/Sources/Disposable/Locked.swift +++ b/Sources/Disposable/Locked.swift @@ -10,7 +10,7 @@ /// 1. `OSAllocatedUnfairLock` /// 2. `NSLock` /// 3. `pthread_mutex_t` -public struct Locked { +struct Locked { // MARK: Lifecycle @@ -19,7 +19,7 @@ public struct Locked { /// - Parameters: /// - value: the instance to be protected by the lock. @inline(__always) - public init(_ value: T) { + init(_ value: T) { self.underlying = Self.make(for: value) } @@ -29,7 +29,7 @@ public struct Locked { /// - Parameters: /// - value: the instance to be protected by the lock. @inline(__always) - public init() where T == Void { + init() where T == Void { self.underlying = Self.make(for: ()) } @@ -37,9 +37,9 @@ public struct Locked { /// Exclusive `{ get set }` access to the protected value. /// - /// > Note: Use ``withLock(action:)-7qgic`` for atomic + /// > Note: Use ``withLock(action:)-7osy0`` for atomic /// read-evaluate-write access to the underlying variable. - @inline(__always) public var value: T { + @inline(__always) var value: T { get { withLock { $0 } } @@ -63,7 +63,7 @@ public struct Locked { /// - Returns: The instance of `aT` created by the action. @inline(__always) @discardableResult - public func withLock(action: (inout T) throws -> aT) rethrows -> aT { + func withLock(action: (inout T) throws -> aT) rethrows -> aT { let lock = underlying lock.lock() defer { lock.unlock() } @@ -85,7 +85,7 @@ extension Locked where T == Void { /// - Returns: The instance of `aT` created by the action. @inline(__always) @discardableResult - public func withLock

(action: () throws -> P) rethrows -> P { + func withLock

(action: () throws -> P) rethrows -> P { let lock = underlying lock.lock() defer { lock.unlock() } @@ -94,15 +94,15 @@ extension Locked where T == Void { /// Take exclusive access to the lock. /// - /// Prefer ``withLock(action:)-7ntrz``. + /// Prefer ``withLock(action:)-7osy0``. @inline(__always) - public func lock() { + func lock() { underlying.lock() } /// Release exclusive access taken with ``lock()`` @inline(__always) - public func unlock() { + func unlock() { underlying.unlock() } } diff --git a/Sources/Disposable/Task.swift b/Sources/Disposable/Task.swift index b8474c5..0462840 100644 --- a/Sources/Disposable/Task.swift +++ b/Sources/Disposable/Task.swift @@ -10,8 +10,8 @@ extension Disposables { /// A wrapped for Swift's native `Task` which implements `Disposable`. /// /// Create a *running* wrapped `Task` with - /// ``Disposables/Task/attached(priority:action:onDispose:)-7m9sh`` - /// or ``Disposables/Task/attached(priority:action:onDispose:)-7m9sh``. + /// ``Disposables/Task/attached(priority:action:onDispose:)-5ejvn`` + /// or ``Disposables/Task/attached(priority:action:onDispose:)-3kr88``. public struct Task: Disposable, Sendable where Success: Sendable, Failure: Error {