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
Prev Previous commit
Next Next commit
feat: sendables everywhere
  • Loading branch information
reddavis committed Sep 22, 2022
commit 01f7a873373c3a5ac0f78ab40cc23001ecc7415d
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public actor CurrentElementAsyncSequence<Element>: AsyncSequence where Element:

// MARK: Stream

fileprivate struct _Stream<Element>: AsyncSequence, Sendable where Element: Sendable {
fileprivate struct _Stream<Element>: AsyncSequence {
private var stream: AsyncStream<Element>!
private var continuation: AsyncStream<Element>.Continuation!

Expand Down Expand Up @@ -102,3 +102,5 @@ fileprivate struct _Stream<Element>: AsyncSequence, Sendable where Element: Send
self.continuation.finish(with: element)
}
}

extension _Stream: Sendable where Element: Sendable {}
2 changes: 1 addition & 1 deletion Asynchrone/Source/Sequences/Fail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/// // Prints:
/// // Error!
/// ```
public struct Fail<Element, Failure>: AsyncSequence where Failure: Error {
public struct Fail<Element, Failure>: AsyncSequence, Sendable where Failure: Error {
private let error: Failure
private var hasThownError = false

Expand Down
38 changes: 21 additions & 17 deletions Asynchrone/Source/Sequences/SequenceAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,37 @@ public struct SequenceAsyncSequence<P: Sequence>: AsyncSequence {

/// Creates an async iterator that emits elements of this async sequence.
/// - Returns: An instance that conforms to `AsyncIteratorProtocol`.
public func makeAsyncIterator() -> SequenceAsyncSequenceIterator<P> {
public func makeAsyncIterator() -> Iterator {
.init(self.sequence.makeIterator())
}
}

extension SequenceAsyncSequence: Sendable where P: Sendable {}

// MARK: SequenceAsyncSequenceIterator
// MARK: Iterator

public struct SequenceAsyncSequenceIterator<P: Sequence>: AsyncIteratorProtocol {
private var iterator: P.Iterator

// MARK: Initialization

public init(_ iterator: P.Iterator) {
self.iterator = iterator
}

// MARK: AsyncIteratorProtocol

/// Produces the next element in the sequence.
/// - Returns: The next element or `nil` if the end of the sequence is reached.
public mutating func next() async -> P.Element? {
self.iterator.next()
extension SequenceAsyncSequence {
public struct Iterator: AsyncIteratorProtocol {
private var iterator: P.Iterator

// MARK: Initialization

init(_ iterator: P.Iterator) {
self.iterator = iterator
}

// MARK: AsyncIteratorProtocol

/// Produces the next element in the sequence.
/// - Returns: The next element or `nil` if the end of the sequence is reached.
public mutating func next() async -> P.Element? {
self.iterator.next()
}
}
}

extension SequenceAsyncSequence.Iterator: Sendable where P.Iterator: Sendable {}

// MARK: Sequence

public extension Sequence {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ public struct ThrowingPassthroughAsyncSequence<Element>: AsyncSequence {
self.continuation.finish(with: element)
}
}

extension ThrowingPassthroughAsyncSequence: Sendable where Element: Sendable {}