Skip to content

Commit

Permalink
update documentation and swift version syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-zethraeus committed Jul 3, 2023
1 parent 967c032 commit a4348e7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 32 deletions.
20 changes: 19 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,29 @@ let package = Package(
],
targets: [
.target(
name: "Disposable"
name: "Disposable",
dependencies: [],
swiftSettings: Env.swiftSettings
),
.testTarget(
name: "DisposableTests",
dependencies: ["Disposable"]
),
]
)

// 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
}()
}
16 changes: 15 additions & 1 deletion Sources/Disposable/Bridging/CombineExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Sources/Disposable/ConvenienceStages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]())

}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Disposable/Disposable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
14 changes: 0 additions & 14 deletions Sources/Disposable/DisposableBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#if canImport(Combine)
import Combine
#endif

// MARK: - DisposableBuilder

@resultBuilder
Expand All @@ -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] {
[]
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/Disposable/Locked.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// 1. `OSAllocatedUnfairLock`
/// 2. `NSLock`
/// 3. `pthread_mutex_t`
public struct Locked<T> {
struct Locked<T> {

// MARK: Lifecycle

Expand All @@ -19,7 +19,7 @@ public struct Locked<T> {
/// - 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)
}

Expand All @@ -29,17 +29,17 @@ public struct Locked<T> {
/// - 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: ())
}

// MARK: Public

/// 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 }
}
Expand All @@ -63,7 +63,7 @@ public struct Locked<T> {
/// - Returns: The instance of `aT` created by the action.
@inline(__always)
@discardableResult
public func withLock<aT>(action: (inout T) throws -> aT) rethrows -> aT {
func withLock<aT>(action: (inout T) throws -> aT) rethrows -> aT {
let lock = underlying
lock.lock()
defer { lock.unlock() }
Expand All @@ -85,7 +85,7 @@ extension Locked where T == Void {
/// - Returns: The instance of `aT` created by the action.
@inline(__always)
@discardableResult
public func withLock<P>(action: () throws -> P) rethrows -> P {
func withLock<P>(action: () throws -> P) rethrows -> P {
let lock = underlying
lock.lock()
defer { lock.unlock() }
Expand All @@ -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()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Disposable/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Success, Failure>: Disposable, Sendable where Success: Sendable,
Failure: Error
{
Expand Down

0 comments on commit a4348e7

Please sign in to comment.