* 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
* #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
* First pass at some documentation for AsyncChannel
* Apply suggestions from code review
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Manually line break docs
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* First pass at some documentation for AsyncBufferSequence
* Apply suggestions from code review
Co-authored-by: Chris Adamson <invalidname@gmail.com>
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* slight adjustments to make docc rendering of AsyncBufferedByteIterator documentation nicer
* Apply suggestions from code review
Co-authored-by: Chris Adamson <invalidname@gmail.com>
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Rebase guides WIP to avoid source changes
* Add prose for debounce and throttle
* Add an alterantive for debounce
* Starts to prose for reductions
* Add effect listings for all types
* Add some examples for reductions
* Update Guides/Channel.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Channel.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Channel.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Channel.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Collections.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Throttle.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Throttle.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Guides/Throttle.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Update Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Adjust events to elements for channels
* Add a bit more detail to the README and a start to the guide for Task.select
* Chunked updates
* Add a getting started section to the README
* Add some more prose for Channel
* Update Guides/RemoveDuplicates.md
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Apply suggestions from code review
Co-authored-by: Chris Adamson <invalidname@gmail.com>
* Add some brief prose for Compacted
* reductions could be named scan
* spelling and correctness fixes
* Apply @kperryua's suggestion for changing the intro of Compacted
* Add some brief prose for Timer
* Apply suggestions from code review for README
Co-authored-by: Tony Parker <anthony.parker@apple.com>
* Add some brief prose for RemoveDuplicates
* Fleshing out of `Joined`
Co-authored-by: Chris Adamson <invalidname@gmail.com>
Co-authored-by: Kevin Perry <kperry@apple.com>
Co-authored-by: Tony Parker <anthony.parker@apple.com>
* 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>
* Resolve a race condition that caused repeated testing of channel cancellation to sometimes hang
* Better name for removal for cancellation in inner Async(Throwing)Channel
* 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