Compare commits

..
6 Commits
Author SHA1 Message Date
Faris Basha TM 088f92a30c Fix dead links to moved source files and the Collections guide (#469)
The channel and debounce sources moved into Channels/ and Debounce/,
AsyncChunksOfCountAndSignalSequence.swift is now
AsyncChunksOfCountOrSignalSequence.swift, and the Collections guide
lives in the DocC catalog, so these links return 404.
2026-11-18 06:44:13 -08:00
Rick Newton-Rogers 74a48bddc6 Revert "Bump swiftlang/github-workflows to 0.0.18 (#467)" (#468)
This reverts commit ba5872bfcb.
2026-11-16 19:27:54 -05:00
Rick Newton-Rogers ba5872bfcb Bump swiftlang/github-workflows to 0.0.18 (#467)
The new workflows use macOS Golden Gate rather than macOS Tahoe by default.
2026-11-16 19:22:41 -05:00
Hokila Jan cbde9aed74 Preserve debounce upstream failure without outstanding demand (#451)
* Preserve debounce upstream failure without demand

* Add debounce upstream failure regression tests
2026-10-05 16:11:40 +02:00
Tessaro d9c26817af Fix AsyncAlgorithms 1.3 availability macro typo (#453)
The `#else` branch declared `AsyncAlgorithms_v1_3` with the macro name
`AsyncAlgorithms 1.2`, so that branch defined `AsyncAlgorithms 1.2` twice
and never defined `AsyncAlgorithms 1.3`.

Issue: https://github.com/apple/swift-async-algorithms/issues/452
2026-10-02 14:35:24 +02:00
Aniket 822cfb8331 Fix MultiProducerSingleConsumerAsyncChannel doc examples to use takeChannel() (#460)
The stored channel property of ChannelAndStream is intentionally
internal, so the documented consume channelAndSource.channel snippet
fails to compile for clients. The supported API is takeChannel(); use
it in both doc examples.

Signed-off-by: Aniket <aniketkomailkro@gmail.com>
2026-10-02 14:04:26 +02:00
9 changed files with 84 additions and 14 deletions

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ for await (first, second) in (1...5).async.adjacentPairs() {
// First: 4, Second: 5
```
It composes well with the [Dictionary.init(_:uniquingKeysWith:)](https://github.com/apple/swift-async-algorithms/blob/main/Guides/Collections.md) API that deals with `AsyncSequence` of tuples.
It composes well with the [Dictionary.init(_:uniquingKeysWith:)](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Collections.md) API that deals with `AsyncSequence` of tuples.
```swift
Dictionary(uniqueKeysWithValues: url.lines.adjacentPairs())
+2 -2
View File
@@ -3,8 +3,8 @@
* Author(s): [Philippe Hausler](https://github.com/phausler)
[
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncChannel.swift),
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncThrowingChannel.swift) |
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/Channels/AsyncChannel.swift),
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift) |
[Tests](https://github.com/apple/swift-async-algorithms/blob/main/Tests/AsyncAlgorithmsTests/TestChannel.swift)
]
+1 -1
View File
@@ -5,7 +5,7 @@
* Implementation: [
[By group](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift),
[On projection](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncChunkedOnProjectionSequence.swift),
[Count and signal](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncChunksOfCountAndSignalSequence.swift)
[Count and signal](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncChunksOfCountOrSignalSequence.swift)
[Tests](https://github.com/apple/swift-async-algorithms/blob/main/Tests/AsyncAlgorithmsTests/TestChunk.swift)
]
[
+1 -1
View File
@@ -5,7 +5,7 @@
* Status: **Accepted**
* Implementation:
[
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncDebounceSequence.swift) |
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift) |
[Tests](https://github.com/apple/swift-async-algorithms/blob/main/Tests/AsyncAlgorithmsTests/TestDebounce.swift)
]
[
+1 -1
View File
@@ -14,7 +14,7 @@ let AsyncAlgorithms_v1_3 =
#else
let AsyncAlgorithms_v1_1 = "AvailabilityMacro=AsyncAlgorithms 1.1:macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0"
let AsyncAlgorithms_v1_2 = "AvailabilityMacro=AsyncAlgorithms 1.2:macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0"
let AsyncAlgorithms_v1_3 = "AvailabilityMacro=AsyncAlgorithms 1.2:macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0"
let AsyncAlgorithms_v1_3 = "AvailabilityMacro=AsyncAlgorithms 1.3:macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0"
#endif
let availabilityMacros: [SwiftSetting] = [
@@ -32,7 +32,7 @@ for await (first, second) in (1...5).async.adjacentPairs() {
// First: 4, Second: 5
```
It composes well with the [Dictionary.init(_:uniquingKeysWith:)](https://github.com/apple/swift-async-algorithms/blob/main/Guides/Collections.md) API that deals with `AsyncSequence` of tuples.
It composes well with the [Dictionary.init(_:uniquingKeysWith:)](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Collections.md) API that deals with `AsyncSequence` of tuples.
```swift
Dictionary(uniqueKeysWithValues: url.lines.adjacentPairs())
@@ -399,9 +399,9 @@ struct DebounceStateMachine<Base: AsyncSequence & Sendable, C: Clock>: Sendable
return .none
case .waitingForDemand(let task, .none, let clockContinuation, .none):
// We don't have any buffered element so we can just go ahead
// and transition to finished and cancel everything
self.state = .finished
// We don't have outstanding demand to deliver the error to, so store it
// until the downstream calls next and cancel everything.
self.state = .upstreamFailure(error: error)
return .cancelTaskAndClockContinuation(
task: task,
@@ -37,13 +37,13 @@ public struct MultiProducerSingleConsumerAsyncChannelAlreadyFinishedError: Error
/// Afterwards, you can pass the source to the producer and the channel to the consumer.
///
/// ```
/// let channelAndSource = MultiProducerSingleConsumerAsyncChannel.makeChannel(
/// var channelAndSource = MultiProducerSingleConsumerAsyncChannel.makeChannel(
/// of: Int.self,
/// backpressureStrategy: .watermark(low: 2, high: 4)
/// )
///
/// // The channel and source can be extracted from the returned type
/// let channel = consume channelAndSource.channel
/// let channel = channelAndSource.takeChannel()
/// let source = consume channelAndSource.source
/// ```
///
@@ -127,11 +127,11 @@ public struct MultiProducerSingleConsumerAsyncChannel<Element, Failure: Error>:
/// components from it.
///
/// ```swift
/// let channelAndSource = MultiProducerSingleConsumerAsyncChannel.makeChannel(
/// var channelAndSource = MultiProducerSingleConsumerAsyncChannel.makeChannel(
/// of: Int.self,
/// backpressureStrategy: .watermark(low: 5, high: 10)
/// )
/// var channel = consume channelAndSource.channel
/// var channel = channelAndSource.takeChannel()
/// var source = consume channelAndSource.source
/// ```
@frozen
@@ -12,6 +12,10 @@
import XCTest
import AsyncAlgorithms
private struct DebounceTestError: Error, Equatable, Sendable {
let value: Int
}
final class TestDebounce: XCTestCase {
#if canImport(Darwin) || canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
func test_delayingValues() throws {
@@ -58,6 +62,72 @@ final class TestDebounce: XCTestCase {
}
}
func test_upstreamFailureWithoutOutstandingDemand() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
throw XCTSkip("Skipped due to Clock/Instant/Duration availability")
}
validate {
"a^"
$0.inputs[0].debounce(for: .steps(0), clock: $0.clock)
"a,,,^"
}
}
func test_upstreamFailureWithoutElementsPreservesError() async throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
throw XCTSkip("Skipped due to Clock/Instant/Duration availability")
}
let expectedError = DebounceTestError(value: 1)
let (stream, source) = AsyncThrowingStream<Int, Error>.makeStream()
source.finish(throwing: expectedError)
var iterator = stream.debounce(for: .milliseconds(10), clock: .continuous).makeAsyncIterator()
do {
_ = try await iterator.next()
XCTFail("Expected the upstream error")
} catch let error as DebounceTestError {
XCTAssertEqual(error, expectedError)
}
let result = try await iterator.next()
XCTAssertNil(result)
}
func test_upstreamFailureAfterElementAndWithoutDemandPreservesError() async throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
throw XCTSkip("Skipped due to Clock/Instant/Duration availability")
}
let expectedError = DebounceTestError(value: 2)
let (stream, source) = AsyncThrowingStream<Int, Error>.makeStream()
source.yield(1)
let finisher = Task {
try? await Task.sleep(for: .milliseconds(100))
source.finish(throwing: expectedError)
}
defer { finisher.cancel() }
var iterator = stream.debounce(for: .milliseconds(10), clock: .continuous).makeAsyncIterator()
let first = try await iterator.next()
XCTAssertEqual(first, 1)
// The upstream fails while the consumer has no outstanding demand.
try await Task.sleep(for: .milliseconds(300))
do {
_ = try await iterator.next()
XCTFail("Expected the upstream error")
} catch let error as DebounceTestError {
XCTAssertEqual(error, expectedError)
}
// Consuming the failure completes the iterator; it must not produce another value
// or resume completion more than once.
let result = try await iterator.next()
XCTAssertNil(result)
}
func test_noValues() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
throw XCTSkip("Skipped due to Clock/Instant/Duration availability")