* 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(_:)
* 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
* 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
* #113 Define the first element of throttled sequences by not exceeding the rate (and fix a expectation misalignment of events)
* Update guide for throttle referencing the first element and duration measurement
* Implement source location information for pairwise block builders
* Enable better source locations for latest validation diagrams
* Use the new naming for partial builders
* Ensure pairwise builder expressions preserve source locations
* A full knobs-and-dials buffering strategy transformation
* Refine the AsyncBuffer type to require actor and add some additonal tests for custom buffer types
* Migrate the internal state to an actor
* Remove default unbounded policy from buffers
* Remove some dead code tests and fix space removal to avoid superfluous checks
* Simplification of nominal state machine, which helps eliminate actor interleaving issues. Fixed error/termination handling. Validation diagram tests, using “delay next” operators
* Most robust behavior when multiple tasks are concurrently accessing the iterator
* Removed Envelope, added base iterator Sendable requirement, and added conditional Sendable conformances
* Minor future-proofing
Co-authored-by: Kevin Perry <kperry@apple.com>
* Add a performance tuned asynchronous iterator for creeating asynchronous byte sequences
* Some spelling fixes and language clarity improvements
* Add some more detail on the docs for the `AsyncBufferedByteIterator` initializer
* Move the storage to a usable from inline type
* Add sequences that chunk values into collections based on a variety of criteria
* Factor out Merge2 logic so its termination behavior can be customized
* Rewrite AsyncChunksOfCountAndTriggerSequence in terms of the newly configurable merge state machine
* Name changes
* Fixed tests
* Enable chunked(byTime:) functions
* Broken up into one file per sequence
* implement a sequence fir debouncing incoming events to an expected quiessence duration
* Ensure debouced sequences are sendable and update testing to the new validate method
* Add hangover tests and cancel sleep per iteration of production
* Add a detailed proposal like guide for MarbleDiagram
* Slight spacing change
Co-authored-by: kperryua <kperry@apple.com>
* Fix some pluralization agreement
Co-authored-by: kperryua <kperry@apple.com>
* Clarify the testing of merge and add a future direction for unordered groups
* rename the diagram system to a more general 'validate' based name
* Spelling fixes
* Grammar fixes for credits
Co-authored-by: kperryua <kperry@apple.com>
* Support cancellation for marble diagrams
* Add a timer based async sequence
* Test skewing events by sleeps inside the map
* A less confusing skew cancellation tick
* Split the marble diagram code out into their own files for easier refactoring
* Update latest landing InstantProtocol definition stub
* Migrate to a per Task based queue system to avoid blocking valid future jobs
* Factor inputs to be specialized waits for side tracking
* Add grouping support
* Add tests for grouping and parse failures
* Fixup misstep in package definition for clock stub imports for the marable diagrams
* Add descriptions for partial iterations for debugging aides
* Simplify Task.select implementation to handle continuations more encapsulatedly
* Add descriptions for WorkQueue items for debugging and use stable work queue drains
* Rework marble diagrams to account for task execution
* Add marble diagram tests to validate failure paths
* Test for space no-op in marable diagram DSL
* Factor out parsing into events and generalize