Skip to content
CAI
Software that uses CAICheck a score

apple/swift-async-algorithms

67.5

Adequate · 14 November 2026

16.9k

lines of production code

Swift

primary language

5

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is a Swift library providing a comprehensive suite of operators and utilities for manipulating asynchronous sequences. It enables developers to combine, transform, and buffer data streams through features like merging, zipping, debouncing, and chunking, while also offering robust channel implementations for producer-consumer communication. The library includes specialized modules for streaming I/O and multi-producer channels with backpressure control, supported by extensive testing infrastructure for validation and performance benchmarking.

How it got here

2022 — Async sequence operators and testing infrastructure

12 changes.

This period focused on expanding the AsyncAlgorithms library with new operators for combining, merging, and processing asynchronous sequences, such as zip, merge, combineLatest, and debounce. Significant effort was also dedicated to building a robust testing ecosystem, including comprehensive unit tests, performance benchmarks, and a visual diagram DSL for validating sequence behavior.

2023–2026 — AsyncAlgorithms expansion and AsyncStreaming introduction

10 changes.

This period focused on expanding the AsyncAlgorithms library with new sequence operators like buffer, interspersed, and flatMapLatest, alongside significant internal refactoring to improve concurrency safety and memory efficiency. It also introduced the new AsyncStreaming module, providing protocols and channels for managing reader/writer streams and bidirectional communication with backpressure support.

Features

Add AsyncSequence.flatMapLatest operator

The \AsyncSequence\ protocol now includes a \flatMapLatest\ method (available in AsyncAlgorithms 1.3) that transforms elements into new asynchronous sequences, emitting only elements from the most recently produced inner sequence. When a new element is emitted by the source sequence, any ongoing iteration on the previous inner sequence is automatically cancelled, and iteration begins on the new one. This allows consumers to easily handle scenarios where only the latest result of an asynchronous transformation is relevant, discarding stale or in-flight results.

Sources/AsyncAlgorithms/FlatMapLatest · high confidence

Add interspersed method to AsyncSequence

The \AsyncSequence\ protocol now includes an \interspersed\ method that returns a new asynchronous sequence with a specified separator inserted between elements. This feature supports inserting a static separator value, a synchronous closure, or an asynchronous closure to generate separators, and allows configuring the frequency of insertion via an \every\ parameter.

Sources/AsyncAlgorithms/Interspersed · high confidence

Introduce AsyncSequence validation diagram DSL and test infrastructure

The \Sources/AsyncSequenceValidation\ module now provides a new \AsyncSequenceValidationDiagram\ result builder and supporting types (Clock, Event, Expectation, Input, Test, Theme) that allow users to define asynchronous sequence tests using a visual diagram syntax. This DSL lets you specify expected inputs, operations, and outputs with tick-based timing, grouping, and error handling, while the internal \WorkQueue\ and \TaskDriver\ components drive the simulated clock and task execution to validate behavior against the specified diagram.

Sources/AsyncSequenceValidation · high confidence

Introduce MultiProducerSingleConsumerAsyncChannel with watermark backpressure

Adds the MultiProducerSingleConsumerAsyncChannel type (available on Swift 6.1+), a multi-producer, single-consumer async channel that supports watermark-based backpressure strategies. The channel allows multiple producers to send values while suspending producers when the buffer exceeds a high watermark and resuming them when it drops below a low watermark. It includes internal helpers like Disconnected for moving non-Sendable values across isolation regions and \_TinyArray for optimized storage, along with termination callbacks and error handling for finished channels.

Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel · high confidence

Introduce \`zip\` for combining two or three async sequences

Added \zip\ functions and their supporting types (\AsyncZip2Sequence\, \AsyncZip3Sequence\, \ZipStateMachine\, \ZipStorage\) to concurrently await and emit tuples of values from two or three \AsyncSequence\ inputs. The implementation uses a state machine and task group to manage upstream iteration and downstream demand, ensuring thread-safe coordination of the combined streams.

Sources/AsyncAlgorithms/Zip · high confidence

Introduce combineLatest for two and three asynchronous sequences

Adds the \combineLatest(\:\:)\ and \combineLatest(\:\:\_:)\ functions, which create asynchronous sequences that emit tuples of the latest values from two or three base \AsyncSequence\s. The implementation includes \AsyncCombineLatest2Sequence\ and \AsyncCombineLatest3Sequence\ types, along with the underlying \CombineLatestStateMachine\ and \CombineLatestStorage\ to manage concurrent iteration, buffering, and cancellation. These sequences emit values only after each base has emitted at least one value and finish when all bases are complete.

Sources/AsyncAlgorithms/CombineLatest · high confidence

Introduce debounce operator for asynchronous sequences

Adds a new \debounce\ method to \AsyncSequence\ that emits the latest element from the source sequence only after a specified quiescence period has elapsed. This allows users to filter out rapid, successive emissions by waiting for a pause in the data stream, configurable with a specific interval, optional tolerance, and a pluggable \Clock\ for testing or custom timing control.

Sources/AsyncAlgorithms/Debounce · high confidence

Introduce merge operator for two and three asynchronous sequences

Added \AsyncMerge2Sequence\ and \AsyncMerge3Sequence\ types, along with their corresponding \merge\ functions, allowing users to combine elements from two or three upstream \AsyncSequence\s into a single merged asynchronous sequence. The implementation uses a shared \MergeStateMachine\ and \MergeStorage\ to coordinate consumption of the upstream sequences, handling buffering, cancellation, and error propagation.

Sources/AsyncAlgorithms/Merge · high confidence

Introduces AsyncStreaming module with reader/writer protocols and duplex channel

Adds the new \AsyncStreaming\ module (available on macOS 27.0, iOS 27.0, watchOS 27.0, tvOS 27.0, visionOS 27.0, and requiring Swift 6.4+) providing \AsyncReader\ and \CallerAsyncReader\ protocols for consuming streams with callee-managed and caller-managed buffering, respectively, along with \AsyncWriter\ and \CallerAsyncWriter\ protocols for producing streams. The module includes \pipe\ convenience methods to transfer data between readers and writers, adapters to convert between caller-managed and callee-managed buffering styles, and a \DuplexAsyncChannel\ for bidirectional in-memory communication with independent backpressure strategies.

Sources/AsyncStreaming · high confidence

New AsyncSequence operators and utilities

The library introduces a suite of new asynchronous sequence operators: \adjacentPairs()\ to iterate over consecutive element pairs; \compacted()\ to filter out nil values; \chain(\:\:)\ and \chain(\:\:\:)\ to concatenate two or three sequences; \joined()\ and \joined(separator:)\ to flatten nested sequences; \reductions(\:)\ (inclusive) and \reductions(into:\:)\ (exclusive) to emit intermediate accumulation results; \chunked(ofCount:)\, \chunked(by:)\, and \chunked(on:)\ to group elements into collections based on count, grouping predicates, or projection uniqueness; \chunks(ofCount:or:)\ to split sequences by count or signal sequences; and \mapError(\:)\ to transform error types. Additionally, \AsyncBufferedByteIterator\ provides a high-performance iterator for reading byte streams.

Sources/AsyncAlgorithms · high confidence

New buffer operators for AsyncSequence

The \AsyncSequence\ protocol now includes a \buffer(policy:)\ method that allows you to control how elements are buffered during asynchronous iteration. You can choose from four policies: \bounded\ (pauses the upstream when the buffer is full), \unbounded\ (no limit), \bufferingNewest\ (discards oldest elements when full), and \bufferingOldest\ (discards newest elements when full). This feature is available starting with AsyncAlgorithms 1.0.

Sources/AsyncAlgorithms/Buffer · high confidence

Behavioural changes

Internal optimizations for concurrency safety and memory efficiency

This change introduces two internal helper types to improve the library's robustness and performance. A new \Disconnected\ struct provides a safe mechanism to move non-Sendable values across isolation boundaries, addressing data race concerns in concurrent contexts. Additionally, a \\_TinyArray\ collection is added to optimize storage for sequences containing zero or one element by keeping them inline without heap allocation, reducing memory overhead for small collections.

Sources/AsyncAlgorithms/Internal · high confidence

Reimplemented channels with a state machine to fix potential deadlocks

The \AsyncChannel\ and \AsyncThrowingChannel\ implementations in the Channels module have been rewritten using a dedicated \ChannelStateMachine\ and \ChannelStorage\ to manage producer-consumer synchronization. This architectural change replaces the previous implementation to eliminate potential deadlocks that could occur when resuming continuations while holding locks, ensuring more robust back-pressure handling and concurrency safety for task-to-task communication.

Sources/AsyncAlgorithms/Channels · high confidence

Swift 5.8 support with strict concurrency and availability macros

The package now includes a dedicated Swift 5.8 build configuration that enables strict concurrency checking and defines availability macros for AsyncAlgorithms versions 1.0 through 1.3, mapping specific API sets to macOS 10.15/iOS 13.0 and later platforms including visionOS 2.0. This upgrade also updates the dependency on swift-collections to version 1.1.0 and refines the target structure by removing the separate AsyncSequenceValidation and AsyncAlgorithms\_XCTest product libraries in favor of internal targets, while adding support for additional platforms like Android, Linux, and WASI in test conditions.

(repo-wide) · high confidence

Test coverage

Added test support utilities for AsyncAlgorithms; Added tests for AsyncInterspersedSequence; Added tests for AsyncStreaming readers, writers, and channels; Added tests for MultiProducerSingleConsumerAsyncChannel source lifecycle; Added throughput performance tests for AsyncAlgorithms; Added unit tests for AsyncAlgorithms operators; Added validation test helpers for AsyncSequenceValidation.

Dependencies

Add AsyncStreaming product and update swift-collections dependency

The package now exposes a new \AsyncStreaming\ library product, which depends on \BasicContainers\, \ContainersPreview\, and \DequeModule\ from the \swift-collections\ package. The \swift-collections\ dependency is explicitly set to version 1.7.0, and the package configuration includes an \UnstableAsyncStreaming\ trait to enable source-unstable components in the \\_AsyncStreaming\ module.

(dependencies) · high confidence

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 67 → 68 (+0.8)
  • Rubric changed (rubric-2026.10.5 → rubric-2026.11.4) — scores are not directly comparable.

Lenses

  • Code Health 82 → 77 (-4.7)
  • Architecture 89 → 94 (+5.4)
  • Maturity 65 → 72 (+7.8)
  • Readiness 56 → 55 (-0.8)
  • Security 100 → 100 (+0.0)
  • Performance 91 → 85 (-6.4)

Resolved (26)

  • Classify ADR enforcement: AdjacentPairs (Evolution/0005-adjacent-pairs.md)
  • Classify ADR enforcement: AsyncBufferedByteIterator (Evolution/0008-bytes.md)
  • Classify ADR enforcement: AsyncSyncSequence (Evolution/0009-async.md)
  • Classify ADR enforcement: Buffer (Evolution/0010-buffer.md)
  • Classify ADR enforcement: Chain (Evolution/0007-chain.md)
  • Classify ADR enforcement: Channel (Evolution/0012-channel.md)
  • Classify ADR enforcement: Chunked & Timer (Evolution/0013-chunk.md)
  • Classify ADR enforcement: Combine Latest (Evolution/0006-combineLatest.md)
  • Classify ADR enforcement: Compacted (Evolution/0003-compacted.md)
  • Classify ADR enforcement: Feature name (Evolution/0011-interspersed.md)
  • Classify ADR enforcement: FlatMapLatest (Evolution/0018-flatMapLatest.md)
  • Classify ADR enforcement: Joined (Evolution/0004-joined.md)
  • Classify ADR enforcement: Map Error (Evolution/0017-map-error.md)
  • Classify ADR enforcement: Merge (Evolution/0002-merge.md)
  • Classify ADR enforcement: MultiProducerSingleConsumerAsyncChannel (Evolution/0016-multi-producer-single-consumer-channel.md)
  • Classify ADR enforcement: Rate Limiting (Evolution/0014-rate-limits.md)
  • Classify ADR enforcement: Reductions (Evolution/0015-reductions.md)
  • Classify ADR enforcement: Share (Evolution/0016-share.md)
  • Classify ADR enforcement: Zip (Evolution/0001-zip.md)
  • Duplicated block (18 lines × 2) (Sources/AsyncAlgorithms/Buffer/BoundedBufferStateMachine.swift)
  • …and 6 more

New (53)

  • Duplicated block (20–21 lines × 2) (Sources/AsyncAlgorithms/CombineLatest/CombineLatestStateMachine.swift)
  • Duplicated block (37 lines × 3) (Sources/AsyncAlgorithms/CombineLatest/CombineLatestStorage.swift)
  • Duplicated block (5 lines × 3) (Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift)
  • Duplicated block (7 lines × 2) (Sources/AsyncAlgorithms/Locking.swift)
  • Edited copies of one member (3 members, 15+ corresponding lines) (Sources/AsyncAlgorithms/FlatMapLatest/FlatMapLatestStateMachine.swift)
  • Edited copies of one member (3 members, 40+ corresponding lines) (Sources/AsyncAlgorithms/CombineLatest/CombineLatestStateMachine.swift)
  • Edited copies of one member (4 members, 31+ corresponding lines) (Sources/AsyncAlgorithms/CombineLatest/CombineLatestStateMachine.swift)
  • Edited copy of a member (10 corresponding lines) (Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift)
  • Edited copy of a member (12 corresponding lines) (Sources/AsyncAlgorithms/Buffer/BoundedBufferStorage.swift)
  • Edited copy of a member (13 corresponding lines) (Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift)
  • Edited copy of a member (14 corresponding lines) (Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift)
  • Edited copy of a member (15 corresponding lines) (Sources/AsyncAlgorithms/Buffer/BoundedBufferStateMachine.swift)
  • Edited copy of a member (16 corresponding lines) (Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift)
  • Edited copy of a member (18 corresponding lines) (Sources/AsyncAlgorithms/Buffer/BoundedBufferStateMachine.swift)
  • Edited copy of a member (19 corresponding lines) (Sources/AsyncStreaming/AsyncReader/AsyncReader+collect.swift)
  • Edited copy of a member (19 corresponding lines) (Sources/AsyncStreaming/DuplexChannel/DuplexAsyncChannel.swift)
  • Edited copy of a member (22 corresponding lines) (Sources/AsyncAlgorithms/CombineLatest/CombineLatestStateMachine.swift)
  • Edited copy of a member (23 corresponding lines) (Sources/AsyncStreaming/AsyncReader/AsyncReader+pipe.swift)
  • Edited copy of a member (26 corresponding lines) (Sources/AsyncSequenceValidation/WorkQueue.swift)
  • Edited copy of a member (27 corresponding lines) (Sources/AsyncAlgorithms/Buffer/BoundedBufferStateMachine.swift)
  • …and 33 more

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

apple/swift-async-algorithms was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 14 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit cbde9aed744bc058974e6bd5c0367ca55a6bf97c — the exact code this score is about.
  • Scored under rubric-2026.11.4 — the same rubric and the same method as every other entry in this index.
  • Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.65+preprod-3c33c1882dc1.