118 Commits
Author SHA1 Message Date
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
Francesco Paolo Severino 13713a4ffd Fix compilation errors in AsyncStreaming (#459)
* Fix compilation errors

* Enable traits in CI
2026-09-29 13:33:55 +02:00
Tim Condon 789dcf1f3d fix for Swift Collections 1.7.0 (#456) 2026-09-23 19:56:14 +02:00
Tianhao Liu 11645b8feb [AsyncStreaming] Propagate cancellation to late readers (#449)
* [AsyncStreaming] Propagate cancellation to late readers

Distinguish cancellation from normal source completion when a reader continuation is installed after the channel has already finished.

* [AsyncStreaming] Distinguish terminal read states

Track cancellation separately from an already-consumed terminal result so normal source completion does not throw CancellationError. Precondition on repeated reads after cancellation, a final element, or a source failure, with coverage for each terminal path.

* [AsyncStreaming] Handle pending reader cancellation

Deliver cancellation exactly once when it races with a resumed reader, preserve fused final-element completion, and align terminal-read tests and documentation with the reader contract.

* [AsyncStreaming] Test cancellation through public API

Remove the internal-only state-machine test so the regression suite exercises the supported AsyncStreaming interface without @testable import.
2026-09-03 10:53:07 +02:00
Franz Busch 3da39bbc4e [AsyncStreaming] Redesign AsyncReader.collect to take a target container (#436)
Replace `collect(upTo:body:)` with three target-based overloads: `collect(into:)`, `collect(exactlyInto:)`, and `collect(into:maximumSize:)`. Add `AsyncReaderInsufficientElementsError` for the exact-match shortfall case.
2026-06-25 10:14:54 +02:00
Franz Busch e81438119c [AsyncStreaming] Skip empty buffers in AsyncReader.forEachBuffer (#435)
When a reader signals end-of-stream with an empty buffer, body was still invoked with that empty buffer. Skip the body call when the buffer is empty.
2026-06-23 10:48:22 +02:00
David SmithandFranz Busch 8ee3d2be19 "[AsyncStreaming] Introduce a MultiProducerSingleConsumerChannel and a duplex" + a build fix (#428)
* [AsyncStreaming] Introduce a `MultiProducerSingleConsumerChannel` and a duplex

* Add tests

* Fix UnstableAsyncStreaming test build

---------

Co-authored-by: Franz Busch <f.busch@apple.com>
2026-06-05 17:15:19 -07:00
Franz Busch f4177dcc17 [AsyncStreaming] Add support for final elements (#422)
## Motivation

Real transports deliver structured data alongside end-of-stream and need to fuse the last write with the close. HTTP trailers and gRPC status are the obvious cases. Neither can be expressed by an empty-buffer terminator, and both lose H2/H3/QUIC's DATA+END_STREAM coalescing without a fused call.

## Modification

Adds `FinalElement: ~Copyable = Void` as a primary associated type on all four protocols. `AsyncReader` delivers it via a `consuming FinalElement?` closure parameter; `CallerAsyncReader` returns it. Both writers gain a consuming `finish` carrying the last chunk and the payload in one call.

`forEachBuffer`, `collect`, and the `pipe` variants thread the payload through. `collect` becomes consuming and gains a `Void`-final overload returning just the result.

Adds an "Alternatives considered" entry covering what would break without
this: HTTP body, gRPC, and fused close on H2/H3/QUIC.

## Result

The four protocols can back HTTP body, gRPC streaming, and similar shapes without giving up the fused close. Default `Void` keeps simple conformers unchanged; `Never` marks infinite streams. Custom and `~Copyable` payloads work end to end.
2026-06-02 08:16:01 +02:00
Aditya Singh 268087d1de Correct reductions docs: exclusive variants do not emit the initial value (#423)
The doc comments for the exclusive reductions overloads stated that the
returned sequence is "the initial value followed by the reduced elements".
That does not match the behavior: the iterator pulls a base element before
emitting anything, so the first emitted element is the result of combining
the initial value with the first base element, and the initial value is
never emitted. For an empty base sequence the result is empty rather than a
single-element sequence containing the initial value.

This is the behavior the existing tests already pin down, and changing it
would be source-breaking, so this corrects the documentation to match.
Updates all four exclusive overloads (throwing and non-throwing, value and
into:) and adds empty-base tests covering the now-documented edge case.

The inclusive reductions and the DocC Reductions guide already describe the
actual behavior and are left unchanged.
2026-05-27 15:29:38 +02:00
Franz Busch 3bd2de010e Add new pipe convenience methods for the async readers (#420)
## Motivation

Often developers want to pipe the contents of an async reader into a writer. This is a common scenario in asynchronous streaming APIs. Readers are modeling sources of data where writers are modeling sinks. As an example imagine reading from a network socket and writing the contents into a file. Importantly, the entire operation needs to uphold backpressure.

## Modifications

This PR adds 2 new `pipe` methods to each reader one for each writer type. Depending on the buffer ownership those methods will the pipe operation is copy free, requires a copy or even requires an intermediate allocation for copying. The method parameter labels are trying to express what the operation does.

## Result

It is very easy for developers now to move elements from readers into writers.
2026-05-20 09:49:59 +02:00
Guoye Zhang b2beeb25b4 Change all AsyncStreaming availability from 26.2 to SwiftStdlib 5.0 (#421)
* Change all AsyncStreaming availability from 26.2 to SwiftStdlib 5.0

* Spelling
2026-05-19 10:31:31 +02:00
Franz Busch 6a92272e13 Fix a few new region isolation errors in nightly-main (#419)
* Rework `AsyncStreaming` protocols to use generic `RangeReplaceableContainer` buffers

Replace `InputSpan`/`OutputSpan` with generic `Buffer` associated types constrained to `RangeReplaceableContainer` across all four streaming protocols. This sidesteps the limitation that `OutputSpan` (and other `~Escapable` types) cannot be used in async contexts today, while still allowing conforming types to choose a buffer representation optimized for their use case (e.g. `UniqueArray` for heap-backed storage, or a future stack-allocated container for embedded).

Switch callee-owned protocols from `consuming` to `inout` closure semantics, rename `forEachChunk` to `forEachBuffer`, and move `forEach`/`collect` to future directions in the proposal.

Adds test coverage for `AsyncWriter`, `CallerAsyncReader`, and `EitherError`. Updates all documentation to reflect the new API surface.

* Fix a few new region isolation errors in `nightly-main`

Region isolation got smarter and started diagnosing more potential data races. This PR addresses the new errors. Importantly I had to introduce one `@unchecked Sendable` conformance since we can't yet use `UniqueDeque`
2026-05-14 23:22:27 +02:00
Franz Busch 6783e0f2d2 Adds a new AsyncReader.forEach method (#416)
It is often needed to iterate over all elements of a reader. This PR provides two convenience `forEach` methods to make iteration easier.
2026-05-13 13:20:41 +02:00
Franz Busch d14a83b31f Adds a new AsyncReader.collect method (#415)
Often developers want to collect elements from a reader up to a certain limit. This PR provides a few convenience methods for this.
2026-05-12 23:07:29 +02:00
Franz Busch be2467e0c0 Add new experimental _AsyncStreaming module (#400)
This PR adds an experimental module for asynchronous streaming interfaces as a potential evolution to async sequence. These APIs are considered highly unstable and are mostly for experimentation purposes; hence, they are part of an underscored module and all APIs are hidden behind a trait. I expect significant changes to those APIs to offer more functionality such as gather scatter and more.
2026-05-11 14:58:21 +02:00
5043186441 feat: Add AsyncSequence.flatMapLatest operator (#382)
* feat: Add initial naive implementation of flatMapLatest

This introduces a simplified version of the flatMapLatest operator for AsyncSequence, along with a basic unit test. Note that this implementation uses unstructured concurrency and may have race conditions regarding task cancellation.

* refactor: Implement robust flatMapLatest with generation tracking

- Replaces naive implementation with a thread-safe approach using ManagedCriticalState.
- Introduces generation tracking to prevent race conditions where cancelled inner sequences could yield stale values.
- Adds test_interleaving_race_condition to verify correctness under concurrent load.
- Ensures Swift 6 Sendable compliance.

* refactor: Implement high-performance State Machine for flatMapLatest

- Replaces AsyncThrowingStream implementation with a custom AsyncSequence, Storage, and StateMachine.
- Implements explicit state management using Lock for thread safety.
- Handles concurrency between outer and inner sequences robustly.
- Ensures correct cancellation propagation and error handling.
- Verified with test_interleaving_race_condition.

* refactor: Split flatMapLatest into separate files

- Moves AsyncFlatMapLatestSequence.swift to Sources/AsyncAlgorithms/FlatMapLatest/
- Extracts FlatMapLatestStateMachine and FlatMapLatestStorage into their own files.
- Aligns project structure with other complex operators like CombineLatest and Debounce.

* test: Add comprehensive tests for flatMapLatest

- Added test_outer_throwing to verify outer sequence error propagation
- Added test_inner_throwing to verify inner sequence error propagation
- Added test_cancellation to verify proper cancellation handling
- Added test_empty_outer to verify empty outer sequence handling
- Added test_empty_inner to verify empty inner sequence handling
- Fixed test_simple_sequence to be more robust against timing issues

* fix: Make test_outer_throwing stable

- Changed from synchronous map with throwIf to AsyncThrowingStream
- Added delay to ensure proper error propagation timing
- Fixes intermittent test failures

* refactor: Clean up verbose comments in FlatMapLatestStateMachine

- Removed LLM-style thinking comments
- Kept only essential, professional explanations
- No functional changes, all tests pass

* docs: Add comprehensive guide for flatMapLatest

- Added FlatMapLatest.md documentation guide
- Authored by Peter Friese
- Includes introduction, code samples, and use cases
- Covers search-as-you-type, location-based data, and dynamic config examples
- Compares with similar operators in ReactiveX and Combine

* docs: Add evolution proposal for flatMapLatest

- Created SAA-00nn proposal for flatMapLatest operator
- Includes motivation, detailed design, and examples
- Covers implementation strategy with state machine
- Compares with ReactiveX switchMap and Combine switchToLatest

* mapError - transforming failures (#366)

* Implement AsyncMapErrorSequence

* Update the proposal, implementation and tests with formatting, additional details and modifications for being able to push it to a review

* Foratting and preambles

* Update Copyright date for error sequence

Co-authored-by: Clive <clive819@users.noreply.github.com>

* Update copyright year for mapError tests

Co-authored-by: Clive <clive819@users.noreply.github.com>

* Update availablity and modify the mapError algorithm to be opaque

* Correct pre 6.0 build avail parameters

* Make the formatting of the algorithm accesor a bit more consistent

* Update the 5.8 package builder to define 1.2

* re-run formatter

---------

Co-authored-by: Clive <clive819@gmail.com>
Co-authored-by: Clive <clive819@users.noreply.github.com>

* Update the flatMapLatest proposal and implementation to a pitchable state

* Fix race condition in flatMapLatest and add regression test

* chore: Remove test_output.log and add it to .gitignore

---------

Co-authored-by: Philippe Hausler <phausler@apple.com>
Co-authored-by: Clive <clive819@gmail.com>
Co-authored-by: Clive <clive819@users.noreply.github.com>
2026-03-04 13:58:48 -08:00
Alessio NossaandPhilippe Hausler 2de50036f6 Fix unbuffered share deadlock (#387)
* Introduce test_share_with_no_buffering

* Update test_share_with_no_buffering implementation

* Check limit bigger than 0 in AsyncShareSequence iterate

* Revert "Check limit bigger than 0 in AsyncShareSequence iterate"

This reverts commit 3c9e1ab0ff.

* Check limit bigger than 0 in iterate in AsyncShareSequence

* Hand correct the lint failures in TestShare.swift

* An additional hand-edit lint fix for TestShare.swift

---------

Co-authored-by: Philippe Hausler <phausler@apple.com>
2026-01-26 09:29:41 -08:00
65ed06871b mapError - transforming failures (#366)
* Implement AsyncMapErrorSequence

* Update the proposal, implementation and tests with formatting, additional details and modifications for being able to push it to a review

* Foratting and preambles

* Update Copyright date for error sequence

Co-authored-by: Clive <clive819@users.noreply.github.com>

* Update copyright year for mapError tests

Co-authored-by: Clive <clive819@users.noreply.github.com>

* Update availablity and modify the mapError algorithm to be opaque

* Correct pre 6.0 build avail parameters

* Make the formatting of the algorithm accesor a bit more consistent

* Update the 5.8 package builder to define 1.2

* re-run formatter

---------

Co-authored-by: Clive <clive819@gmail.com>
Co-authored-by: Clive <clive819@users.noreply.github.com>
2026-01-12 12:21:06 -08:00
Franz BuschandJoe Heck 4686d2edd3 Add MultiProducerSingleConsumerChannel (#305)
* Add `AsyncBackpressuredStream` proposal and implementation

# Motivation

The pitch to add external backpressure support to the standard libraries `AsyncStream` got returned for revision since there are larger open questions around `AsyncSequence`. However, having external backpressure in a source asynchronous sequence is becoming more and more important.

# Modification

This PR adds a modified proposal and implementation that brings the Swift Evolution proposal over to Swift Async Algorithms.

* Update proposal and implementation

* Update proposal

* Add example project

* Formatting

* Fix Swift 6.0 build

* Future direction for ~Copyable elements

* Apply formatting

* Fix CI

* Move to 6.1 and update proposal

* Guard tests

* Minor edits to the proposal

* Fix revision order

* FIxup setOnTerminationCallback

* Address review feedback

* Rename to `MultiProducerSingleConsumerAsyncChannel`

* Allow one termination callback per source.

* Fix all sendable warnings

* Remove unbounded strategy, rename copy -> makeAdditionalSource, rename asyncSequence() -> elements(), and move enqueue and cancel to the `CallbackHandle` previously called `CallbackToken`

* Remove Example and fix docs and fix format

* fixes grammar and some word order issues

* Remove unnecessary consume

---------

Co-authored-by: Joe Heck <j_heck@apple.com>
2025-11-18 15:56:41 -08:00
Philippe HauslerandJamie 70c36ce9a1 Share algorithm (#357)
This is an implementation of share; an algorithm for allowing AsyncSequence types to be iterated by multiple consumers. In addition this cleans up the project to be a starting point for the 1.1 release - it fixes the continuous integration support and configurations but has the cost of only supporting 3 active releases (6.0, 6.1, and 6.2). Previous releases are only going to have legacy support via older released versions.

* Fix the remaining todo on hard cancellation vs soft cancellation

* Update Sources/AsyncAlgorithms/AsyncShareSequence.swift

Co-authored-by: Jamie <2119834+jamieQ@users.noreply.github.com>

* Update the implementation of share to handle sendability requirements, address some edge cases and update to the latest version of the discussion around buffering behaviors as well as adding some documentation and commentary

* Add some first drafts at unit tests for verifying share behaviors

* Cleanup some of the documentation and address feedback for implementation details

* Fix merge damage by restoring the changes from @jamieQ

* Fix up some availability issues w.r.t. sendable metatypes

* Add a preamble to SendableMetatypes.swift

* Add a fallback for next (for pre 6.2 swift's)

* Slight adjustments for older compiler builds and expose the sendable metatypes since those are part of documentation

* Update formatting and gate availability for older compilers

* Speculative fix for pre 6.1 compiler crashes by removing the sending keyword

* Revert "Speculative fix for pre 6.1 compiler crashes by removing the sending keyword"

This reverts commit 875fa81bc6.

* Speculative fix for pre 6.1 compiler crashes by removing the sending keyword, and correct sendable metatype shim availability

* Remove block comment for formatting check

* Take a more conservative approach and roll back to only supporting share on 6.2

* Only test share on 6.2 or newer

* roll back to older sendable metatype constraints

* yet another stab at 5.10 visionOS guards

* Formatting pass

* Disable 5.10 builds and leave those to older releases

* Ignore swift-version files to avoid local swiftly toolchain selection from being required by others

* Renumber the proposals and copy share into a guide

* Add a link from the primary doc interface to share

---------

Co-authored-by: Jamie <2119834+jamieQ@users.noreply.github.com>
2025-09-10 10:00:31 -07:00
Philippe Hausler ca38935fc0 Clear up CI issues and testing failures (#365)
* Conditionalize the testing targets for non-windows targets to avoid the TaskDriver requirements
* Some driveby formatting fixes and remove the freebsd target since that is not supported in swiftpm yet
* Rework validation import conditions to dependency conditionals
* Exclude 5.9 workflows and enable macOS testing scheme for CI
* Additional ifdefing out non windows targets for sequence diagram testing and more formatting fixes
2025-09-08 16:23:41 -07:00
Franz Busch d5b49aab17 Apply formatting 2025-03-28 21:59:41 +01:00
Franz Busch cb417003f9 Make throttle underscored (#296)
# Motivation
During the discussion in https://github.com/apple/swift-async-algorithms/issues/248 it became clear that the semantics of `throttle` are not 100% figured out yet.

# Modification
This PR is making `throttle` an underscored API for the upcoming 1.0.0 release. This gives us more time to investigate what exact semantics we want to have.
2023-09-27 08:35:58 -07:00
Philippe Hausler 220f86f792 Ensure the last element of reduction in the throttle is emitted and use appropriate delay (#292) 2023-09-21 08:18:20 -07:00
Franz Busch 281e27c5d0 Fix chunks(countOf: 1) (#293) 2023-09-19 17:23:38 +02:00
Philippe Hausler e639e5c889 Ensure tests work in deployments that host as swift 5.7 (#285) 2023-08-15 15:40:57 -07:00
Franz Busch 7ac31f979f Fix more Sendable warnings and flaky test (#281)
# Motivation
We still had some `Sendable` warnings left under strict Concurrency checking.

# Modification
This PR fixes a bunch of `Sendable` warnings but we still have some left in the validation tests. Additionally, I fixed a flaky test.
2023-08-01 16:09:34 +01:00
Philippe Hausler 156bb4bf49 Reduce the overall warnings from tests (#274)
* Migrate from semaphore style testing waits to async test fulfillment

* Reduce warnings for missing hashable and comparable conformances per availability

* Reduce warnings for executor (still one known warning)
2023-06-23 12:22:23 -07:00
Franz Busch 936a68d012 [AsyncInterspersedSequence] Integrate review feedback (#267)
* Integrate review feedback

This integrates all of the feedback from the review thread. Here is a quick summary:

- Change the trailing separator behaviour. We are no longer returning a separator before we are forwarding the error
- Add a synchronous and asynchronous closure based `interspersed` method.
- Support interspersing every n elements

* Add AsyncThrowingInterspersedSequence

* Update examples
2023-06-23 15:47:25 +02:00
Franz Busch b3394663fd Add Interspersed proposal (#259)
* Clean up old evolution proposals

# Motivation

Our old proposals had a couple of stale links and were not all aligned. This cleans them up.

* Add Interspersed proposal

# Motivation
Add a new evolution proposal for the interspersed algorithm.
2023-05-10 15:18:41 +01:00
Thibault Wittemberg 9cfed92b02 buffer: implement with custom storages (#239) 2023-02-10 11:27:06 -08:00
Franz Busch ca2ac60495 Tolerate cancelling before we create our task (#250)
# Motivation
We switched the point in time when we create tasks to the first call to `next()`. This had the side effect that we can now be cancelled before we even created our task. Which by itself is fine but we didn't handle it in the state machines.

# Modification
Adapt the state machines of `debounce`, `zip`, `merge` and `combineLatest` to handle cancellation before `next()`.

# Result
We shouldn't run into these preconditions anymore.
2023-02-06 17:05:07 +00:00
Thibault Wittemberg 0ebc8058fc channel: re-implement with a state machine (#235) 2023-01-12 09:40:37 -08:00
Philippe Hausler a07a3f41b5 Rename AsyncLazySequence to AsyncSyncSequence per review feedback (#246)
* Rename AsyncLazySequence to AsyncSyncSequence per review feedback

* Rename and number the async proposal
2023-01-10 15:36:42 -08:00
Thibault Wittemberg dd97b564ae tests: harmonize debounce availability (#223) 2022-11-16 10:19:45 -08:00
Philippe Hausler 0174f58455 Cleanup Sendable conformances and @preconcurrency imports to build as strict concurrency clean (#230) 2022-11-16 10:15:26 -08:00
Franz Busch ae26222e86 Rework combineLatest to remove the Sendable constraint on the base iterator (#228)
# Motivation
This follows the recent rework of the `merge` and `zip` algorithms where we dropped the `Sendable` constraint on the `BaseX.AsyncIterator`. This PR now removes the same constraint on `combineLatest`.

# Modification
This PR overhauls the implementation of `combineLatest` with the goal of changing these things:
- Drop the `Sendable` constraint of the base `AsyncIterator`s
- Only create a single `Task`

# Result
`combineLatest` now doesn't require the base `AsyncIterator` to be `Sendable`
2022-11-16 08:49:50 -08:00
Franz Busch 6c6ed33514 Remove Sendability from all Iterators (#219)
# Motivation
We have been discussing this a lot in the other PRs, but in general said that an `AsyncIterator` is the connection between the consuming task and the `AsyncSequence`. If an `AsyncIterator` would be `Sendable` then we don't have that relationship anymore. Therefore, no iterator of an `AsyncIterator` should be `Sendable`.

# Modification
Remove all `Sendable` conformances of the iterators even the conditional ones. We can always add them back later.
2022-10-20 09:34:24 -07:00
Philippe Hausler 2cfb16691a Task.select is no longer used and can potentially impact performance negatively (#217) 2022-10-20 09:34:05 -07:00
Thibault Wittemberg 76b27aebef zip: remove Sendable constraint + limit task creation (#201) 2022-10-10 08:58:22 -07:00
Doug Russell 1bd073999c Deprecation Housekeeping (#206)
`withTaskCancellationHandler<T>(_:, operation:)` -> `withTaskCancellationHandler<T>(operation:onCancel:)`
2022-10-10 08:35:35 -07:00
Franz Busch 314b10c634 Remove AsyncIterator: Sendable requirement from merge (#185)
* Remove `AsyncIterator: Sendable` requirement from merge

# Motivation
Currently a lot of the operator implementations in here that consume other `AsyncSequence`s require the `AsyncIterator` to be `Sendable`. This is mostly due to the fact that we are calling `makeAsyncIterator` on the upstream `AsyncSequence` and then pass that iterator around to various newly spawned `Task`s. This has two downsides:
1. It only allows users to use operators like `merge` if their `AsyncSequence.AsyncIterator` is `Sendable`
2. In merge we are creating new `Task`s for every new demand. Creating `Task`s is not cheap.

My main goal of this PR was to remove the `Sendable` constraint from `merge`.

# Modification
This PR overhauls the complete inner workings of the `AsyncMerge2Sequence`. It does a couple of things:
1. The main change is that instead of creating new `Task`s for every demand, we are creating one `Task` when the `AsyncIterator` is created. This task has as child task for every upstream sequence.
2. When calling `next` we are signalling the child tasks to demand from the upstream
3. A new state machine that is synchronizing the various concurrent operations that can happen
4. Handling cancellation since we are creating a bunch of continuations.

# Result
In the end, this PR swaps the implementation of `AsyncMerge2Sequence` and drops the `Sendable` constraint and passes all tests. Furthermore, on my local performance testing I saw up 50% speed increase in throughput.

# Open points
1. I need to make this sequence re-throwing but before going down that rabbit whole I wanna get buy-in on the implementation.
2. We should discuss and document if `merge` and other operators are hot or cold, i.e. if they only request if they got downstream demand
3. I need to switch `AsyncMerge3Sequence` over to the same iplementation

* Split logic into multiple files, adapt merge3 and incorporate PR feedback

* Add more tests and fix upstream throw behaviour

* Remove internal class from the sequence

* Setup task after first next

* Remove unnecessary tests
2022-10-10 08:34:50 -07:00
Franz Busch f05e450f0b Remove AsyncIterator: Sendable requirement from debounce (#198)
* Remove `AsyncIterator: Sendable` requirement from debounce

# Motivation
The current implementation of `AsyncDebounceSequence` requires the base `AsyncIterator` to be `Sendable`. This is causing two problems:

1. It only allows users to use `debounce` if their `AsyncSequence.AsyncIterator` is `Sendable`
2. In `debounce` we are creating a lot of new `Task`s and reating `Task`s is not cheap.

My main goal of this PR was to remove the `Sendable` constraint from `debounce`.

# Modification
This PR overhauls the implementation of `debounce` and aligns it with the implementation of the open `merge` PR https://github.com/apple/swift-async-algorithms/pull/185 . The most important changes are this:
- I removed the `Sendable` requirement from the base sequences `AsyncIterator`.
- Instead of creating new Tasks for the sleep and for the upstream consumption. I am now creating one Task and manipulate it by signalling continuations
- I am not cancelling the sleep. Instead I am recalculating the time left to sleep when a sleep finishes.

# Result
In the end, this PR swaps the implementation of `AsyncDebounceSequence` and drops the `Sendable` constraint and passes all tests. Furthermore, on my local performance testing I saw up 150% speed increase in throughput.

* Fix https://github.com/apple/swift-async-algorithms/issues/174

* Code review

* Remove lock methods

* Cleanup some unused code

* Setup task after first call to next
2022-09-30 10:12:11 -07:00
Thibault Wittemberg 2b5fbf3c91 [Channel] improve send cancellation (#184)
* asyncChannel: introduce ChannelToken to model Pending and Awaiting

* asyncChannel: harmonize send and next cancellation

* asyncChannel: add .finished as an emission state

* asyncThrowingChannel: harmonize send and next cancellation

* channel: update documentation for cancellation
2022-09-14 15:24:29 -07:00
Thibault Wittemberg 68c8dc285b asyncChainSequence: harmonize unit tests nomenclature (#191) 2022-08-30 10:48:20 -07:00
Thibault Wittemberg cba18c3f88 asyncLazySequence: harmonize unit tests nomenclature (#190) 2022-08-30 10:47:50 -07:00
Thibault Wittemberg f44d02eb26 Improve adjacent pairs unit tests (#179)
* adjacentPairs: improve unit tests

* adjacentPairs: conform indentation to project standards
2022-07-18 09:28:55 -07:00
Thibault Wittemberg 9baff2ad3d [AsyncThrowingChannel] make the fail terminal event non async (#164)
* asyncThrowingChannel: make fail set a terminal state

* asyncChannel: align naming on asyncThrowingChannel

* asyncChannel: remove a test base on Task.sleep

* guides: update Channel with non async fail(_:)
2022-06-27 09:04:37 -07:00
Thibault Wittemberg 6df7fcdd10 merge: improve unit tests (#161) 2022-06-27 09:04:15 -07:00
Philippe Hausler cca423ff03 Remove the disable of availability and mark methods as available to clock/instant/duration (#165)
* Remove the disable of availability and mark methods as available to clock/instant/duration

* Rework availability to be more permissive for tests

* Use hand coded values instead of defines (only available via Darwin versions of Dispatch)

* Adjust additional test availability

* Correct debounce test availability guard

* Update build instructions to indicate Xcode requirements

* Ensure the clock property of the validation diagram is only available for targets that can support it
2022-06-16 13:06:20 -07:00