Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first pass at conforming to Sendable #40

Merged
merged 18 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: first pass at conforming to Sendable
  • Loading branch information
reddavis committed Sep 20, 2022
commit 0e76531e23c929cad48716777854a96f7b9b9b72
16 changes: 11 additions & 5 deletions Asynchrone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1310;
LastUpgradeCheck = 1310;
LastUpgradeCheck = 1400;
TargetAttributes = {
A4C361A9276A5EF200511525 = {
CreatedOnToolsVersion = 13.1;
Expand Down Expand Up @@ -599,6 +599,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = minimal;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -656,6 +657,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = minimal;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -664,11 +666,11 @@
A4C361BF276A5EF200511525 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -692,18 +694,19 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "macosx iphoneos appletvos watchos iphonesimulator appletvsimulator watchsimulator appletvos";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = targeted;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
A4C361C0276A5EF200511525 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -727,6 +730,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "macosx iphoneos appletvos watchos iphonesimulator appletvsimulator watchsimulator appletvos";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = targeted;
SWIFT_VERSION = 5.0;
};
name = Release;
Expand All @@ -740,6 +744,7 @@
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
Expand Down Expand Up @@ -770,6 +775,7 @@
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 8 additions & 4 deletions Asynchrone/Source/Sequences/CatchErrorAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
/// // Prints:
/// // -1
/// ```
public struct CatchErrorAsyncSequence<Base, NewAsyncSequence>: AsyncSequence where
public struct CatchErrorAsyncSequence<Base, NewAsyncSequence>: AsyncSequence
where
Base: AsyncSequence,
NewAsyncSequence: AsyncSequence,
Base.Element == NewAsyncSequence.Element {
Expand All @@ -25,7 +26,7 @@ Base.Element == NewAsyncSequence.Element {

// Private
private let base: Base
private let handler: (Error) -> NewAsyncSequence
private let handler: @Sendable (Error) -> NewAsyncSequence
private var iterator: Base.AsyncIterator
private var caughtIterator: NewAsyncSequence.AsyncIterator?

Expand All @@ -37,7 +38,7 @@ Base.Element == NewAsyncSequence.Element {
/// - output: The element with which to replace errors from the base async sequence.
public init(
base: Base,
handler: @escaping (Error) -> NewAsyncSequence
handler: @Sendable @escaping (Error) -> NewAsyncSequence
) {
self.base = base
self.handler = handler
Expand All @@ -53,6 +54,9 @@ Base.Element == NewAsyncSequence.Element {
}
}

extension CatchErrorAsyncSequence: Sendable
where Base: Sendable, NewAsyncSequence: Sendable, Base.AsyncIterator: Sendable, NewAsyncSequence.AsyncIterator: Sendable {}

// MARK: AsyncIteratorProtocol

extension CatchErrorAsyncSequence: AsyncIteratorProtocol {
Expand Down Expand Up @@ -95,7 +99,7 @@ extension AsyncSequence {
/// - Parameter handler: A closure that takes an Error and returns a new async sequence.
/// - Returns: A `CatchErrorAsyncSequence` instance.
public func `catch`<S>(
_ handler: @escaping (Error) -> S
_ handler: @Sendable @escaping (Error) -> S
) -> CatchErrorAsyncSequence<Self, S> where S: AsyncSequence, S.Element == Self.Element {
.init(base: self, handler: handler)
}
Expand Down
7 changes: 7 additions & 0 deletions Asynchrone/Source/Sequences/ChainAsyncSequenceable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public struct ChainAsyncSequence<P: AsyncSequence, Q: AsyncSequence>: AsyncSeque
}
}

extension ChainAsyncSequence: Sendable
where
P: Sendable,
P.AsyncIterator: Sendable,
Q: Sendable,
Q.AsyncIterator: Sendable {}

// MARK: AsyncIteratorProtocol

extension ChainAsyncSequence: AsyncIteratorProtocol {
Expand Down
12 changes: 12 additions & 0 deletions Asynchrone/Source/Sequences/CombineLatest3AsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public struct CombineLatest3AsyncSequence<P: AsyncSequence, Q: AsyncSequence, R:
}
}

extension CombineLatest3AsyncSequence: Sendable
where
P: Sendable,
P.Element: Sendable,
P.AsyncIterator: Sendable,
Q: Sendable,
Q.Element: Sendable,
Q.AsyncIterator: Sendable,
R: Sendable,
R.Element: Sendable,
R.AsyncIterator: Sendable {}

// MARK: AsyncIteratorProtocol

extension CombineLatest3AsyncSequence: AsyncIteratorProtocol {
Expand Down
9 changes: 9 additions & 0 deletions Asynchrone/Source/Sequences/CombineLatestAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ public struct CombineLatestAsyncSequence<P: AsyncSequence, Q: AsyncSequence>: As
}
}

extension CombineLatestAsyncSequence: Sendable
where
P: Sendable,
P.Element: Sendable,
P.AsyncIterator: Sendable,
Q: Sendable,
Q.Element: Sendable,
Q.AsyncIterator: Sendable {}

// MARK: AsyncIteratorProtocol

extension CombineLatestAsyncSequence: AsyncIteratorProtocol {
Expand Down
2 changes: 0 additions & 2 deletions Asynchrone/Source/Sequences/CurrentElementAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public actor CurrentElementAsyncSequence<Element>: AsyncSequence {
// MARK: Stream

fileprivate struct _Stream<Element>: AsyncSequence {

// Private
private var stream: AsyncStream<Element>!
private var continuation: AsyncStream<Element>.Continuation!

Expand Down
14 changes: 12 additions & 2 deletions Asynchrone/Source/Sequences/DebounceAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import Foundation
/// // 1
/// // 5
/// ```
public struct DebounceAsyncSequence<T: AsyncSequence>: AsyncSequence {
public struct DebounceAsyncSequence<T: AsyncSequence>: AsyncSequence
where
T.AsyncIterator: Sendable {
/// The kind of elements streamed.
public typealias Element = T.Element

Expand Down Expand Up @@ -63,6 +65,10 @@ public struct DebounceAsyncSequence<T: AsyncSequence>: AsyncSequence {
}
}

extension DebounceAsyncSequence: Sendable
where
T: Sendable {}

// MARK: Iterator

extension DebounceAsyncSequence {
Expand Down Expand Up @@ -156,6 +162,10 @@ extension DebounceAsyncSequence {
}
}

extension DebounceAsyncSequence.Iterator: Sendable
where
T.AsyncIterator: Sendable {}

// MARK: Race result

extension DebounceAsyncSequence.Iterator {
Expand All @@ -167,7 +177,7 @@ extension DebounceAsyncSequence.Iterator {

// MARK: Task race coordinator

fileprivate actor TaskRaceCoodinator<Success, Failure: Error> {
fileprivate actor TaskRaceCoodinator<Success, Failure: Error> where Success: Sendable {
private var winner: Task<Success, Failure>?

func isFirstToCrossLine(_ task: Task<Success, Failure>) -> Bool {
Expand Down
6 changes: 5 additions & 1 deletion Asynchrone/Source/Sequences/DelayAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public struct DelayAsyncSequence<T: AsyncSequence>: AsyncSequence {
}
}

extension DelayAsyncSequence: Sendable
where
T: Sendable,
T.AsyncIterator: Sendable {}

// MARK: AsyncIteratorProtocol

extension DelayAsyncSequence: AsyncIteratorProtocol {
Expand All @@ -73,7 +78,6 @@ extension DelayAsyncSequence: AsyncIteratorProtocol {
// MARK: Delay

extension AsyncSequence {

/// Delays emission of all elements by the provided interval.
///
/// ```swift
Expand Down
2 changes: 2 additions & 0 deletions Asynchrone/Source/Sequences/Just.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public struct Just<Element>: AsyncSequence {
}
}

extension Just: Sendable where Element: Sendable {}

// MARK: AsyncIteratorProtocol

extension Just: AsyncIteratorProtocol {
Expand Down
7 changes: 3 additions & 4 deletions Asynchrone/Source/Sequences/Merge3AsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
/// // 3
/// // 4
/// ```
public struct Merge3AsyncSequence<T: AsyncSequence>: AsyncSequence {
public struct Merge3AsyncSequence<T: AsyncSequence>: AsyncSequence
where T: Sendable, T.AsyncIterator: Sendable, T.Element: Sendable {
/// The kind of elements streamed.
public typealias Element = T.Element

// Private
// swiftlint:disable implicitly_unwrapped_optional
private var stream: AsyncThrowingStream<Element, Error>!
private var iterator: AsyncThrowingStream<Element, Error>.Iterator!
// swiftlint:enable implicitly_unwrapped_optional

// MARK: Initialization

Expand All @@ -60,7 +59,7 @@ public struct Merge3AsyncSequence<T: AsyncSequence>: AsyncSequence {
_ r: T
) -> AsyncThrowingStream<Element, Error> {
.init { continuation in
let handler: (
let handler: @Sendable (
_ sequence: T,
_ continuation: AsyncThrowingStream<Element, Error>.Continuation
) async throws -> Void = { sequence, continuation in
Expand Down
10 changes: 3 additions & 7 deletions Asynchrone/Source/Sequences/MergeAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
/// // 8
/// // 9
/// ```
public struct MergeAsyncSequence<T: AsyncSequence>: AsyncSequence {
public struct MergeAsyncSequence<T: AsyncSequence>: AsyncSequence
where T: Sendable, T.Element: Sendable {
/// The kind of elements streamed.
public typealias Element = T.Element

// Private
// swiftlint:disable implicitly_unwrapped_optional
private var stream: AsyncStream<Element>!
private var iterator: AsyncStream<Element>.Iterator!
// swiftlint:enable implicitly_unwrapped_optional

// MARK: Initialization

Expand All @@ -64,7 +63,7 @@ public struct MergeAsyncSequence<T: AsyncSequence>: AsyncSequence {
_ q: T
) -> AsyncStream<Element> {
.init { continuation in
let handler: (
let handler: @Sendable (
_ sequence: T,
_ continuation: AsyncStream<Element>.Continuation
) async throws -> Void = { sequence, continuation in
Expand Down Expand Up @@ -107,12 +106,9 @@ extension MergeAsyncSequence: AsyncIteratorProtocol {
}
}



// MARK: Merge

extension AsyncSequence {

/// An asynchronous sequence that merges two async sequence.
///
/// The sequences are iterated through in parallel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct RemoveDuplicatesAsyncSequence<Base: AsyncSequence>: AsyncSequence
public typealias Element = Base.Element

// A predicate closure for evaluating whether two elements are duplicates.
public typealias Predicate = (_ previous: Base.Element, _ current: Base.Element) -> Bool
public typealias Predicate = @Sendable (_ previous: Base.Element, _ current: Base.Element) -> Bool

// Private
private let base: Base
Expand Down Expand Up @@ -57,6 +57,12 @@ public struct RemoveDuplicatesAsyncSequence<Base: AsyncSequence>: AsyncSequence
}
}

extension RemoveDuplicatesAsyncSequence: Sendable
where
Base: Sendable,
Base.AsyncIterator: Sendable,
Base.Element: Sendable {}

// MARK: AsyncIteratorProtocol

extension RemoveDuplicatesAsyncSequence: AsyncIteratorProtocol {
Expand Down
6 changes: 6 additions & 0 deletions Asynchrone/Source/Sequences/ReplaceErrorAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public struct ReplaceErrorAsyncSequence<Base: AsyncSequence>: AsyncSequence {
}
}

extension ReplaceErrorAsyncSequence: Sendable
where
Base: Sendable,
Base.Element: Sendable,
Base.AsyncIterator: Sendable {}

// MARK: AsyncIteratorProtocol

extension ReplaceErrorAsyncSequence: AsyncIteratorProtocol {
Expand Down
3 changes: 2 additions & 1 deletion Asynchrone/Source/Sequences/SequenceAsyncSequence.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation


/// An async version of `Sequence`. Generally used to turn any `Sequence` into
/// it's async counterpart.
///
Expand Down Expand Up @@ -41,6 +40,8 @@ public struct SequenceAsyncSequence<P: Sequence>: AsyncSequence {
}
}

extension SequenceAsyncSequence: Sendable where P: Sendable {}

// MARK: SequenceAsyncSequenceIterator

public struct SequenceAsyncSequenceIterator<P: Sequence>: AsyncIteratorProtocol {
Expand Down
Loading