# 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.
* 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
* 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.
# Motivation
Swift 5.8 is including a change to how `group.waitForAll()` is working. It now properly waits for all tasks to finish even if one of the tasks throws. We have used `group.waitForAll()` in multiple places and need to change this code accordingly.
# Modification
Switch code from `group.waitForAll()` to `group.next()`.
# Result
This fixes a few stuck tests that we have seen when running against development snapshots.
# 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.
While in the current configuration lock/unlock shouldn't ever fail,
it seems polite to guard against basic misuse in debug builds.
Co-authored-by: Dan Appel <dan_appel@apple.com>
# 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`
# Motivation
I raise on the pitch of `AsyncBufferedByteIterator` on the forums that I think the iterator must not be `Sendable`. The reasoning for this is twofold. First, an iterator is the connection of a consumer to the `AsyncSequence`; therefore, iterators should not be shared since it breaks that assumption. Secondly, the implementation of the `AsyncBufferedByteIterator` can be more straight forward since we don't have to check for unique ownership of the storage.
# Modification
Remove the `Sendable` conformances from `AsyncBufferedByteIterator`.
# Motivation
We recently merged https://github.com/apple/swift-async-algorithms/pull/201 which removed the `Sendable` constraint of the `AsyncIterator` from `zip`. There were some left over comments that we wanted to fix in a follow up. Furthermore, we also can merge the implementations of `zip2` and `zip3` relatively easily. The merging also aids us in understanding what we need from the variadic generics proposals and allows us to give feedback since `zip` is non-trivial to implement with variadic generics.
Lastly, the merged state machine will be a good base for the overhaul of `combineLatest`.
# Modification
This PR merges the state machines from `zip2` and `zip3` into a single one. Furthermore, it addresses some of the open feedback from the last PR.
# Result
We now have a single state machine which is a good foundation for our changes to `combineLatest`.
# 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.
# Motivation
We want to remove any `Sendable` constraints on iterators since they ought to not be passed between `Task`s.
# Modification
Explicitly mark the `AsyncChain2Sequence` to be not `Sendable`.
# Result
Nobody can make this `Sendable`.
# Motivation
We want to remove any `Sendable` constraints on iterators since they ought to not be passed between `Task`s.
# Modification
Explicitly mark the `AsyncAdjacentPairsSequence` to be not `Sendable`.
# Result
Nobody can make this `Sendable`.
* 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
* 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
* 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
* 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(_:)
* asyncChannel: enforce termination for all when finished
* asyncThrowingChannel: enforce termination for all when finished
* asyncChannel: improve unit tests readability
* asyncChannel: adapt the Guide to the new finish behaviour
* asyncChannel: adapt the Guide to the new finish behaviour