sideeffect-io/asyncextensions
**AsyncExtensions** provides a collection of operators that intends to ease the creation and combination of `AsyncSequences`.
Adding AsyncExtensions as a Dependency
To use the AsyncExtensions library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:
.package(url: "https://github.com/sideeffect-io/AsyncExtensions"),Include "AsyncExtensions" as a dependency for your executable target:
.target(name: "<target>", dependencies: ["AsyncExtensions"]),Finally, add import AsyncExtensions to your source code.
Features
Channels
- AsyncBufferedChannel: Buffered communication channel between tasks. The elements are not shared and will be spread across consumers (same as
AsyncStream)
- AsyncThrowingBufferedChannel: Throwing buffered communication channel between tasks
Subjects
- AsyncPassthroughSubject: Subject with a shared output
- AsyncThrowingPassthroughSubject: Throwing subject with a shared output
- AsyncCurrentValueSubject: Subject with a shared output. Maintains and replays its current value
- AsyncThrowingCurrentValueSubject: Throwing subject with a shared output. Maintains and replays its current value
- AsyncReplaySubject: Subject with a shared output. Maintains and replays a buffered amount of values
- AsyncThrowingReplaySubject: Throwing subject with a shared output. Maintains and replays a buffered amount of values
Combiners
zip(::): Zips twoAsyncSequenceinto an AsyncSequence of tuple of elementszip(::_:): Zips threeAsyncSequenceinto an AsyncSequence of tuple of elementszip(_:): Zips any async sequences into an array of elementsmerge(::): Merges twoAsyncSequenceinto an AsyncSequence of elementsmerge(::_:): Merges threeAsyncSequenceinto an AsyncSequence of elementsmerge(_:): Merges anyAsyncSequenceinto an AsyncSequence of elementswithLatest(_:): Combines elements from self with the last known element from an otherAsyncSequencewithLatest(::): Combines elements from self with the last known elements from two other async sequences
Creators
- AsyncEmptySequence: Creates an
AsyncSequencethat immediately finishes - AsyncFailSequence: Creates an
AsyncSequencethat immediately fails - AsyncJustSequence: Creates an
AsyncSequencethat emits an element an finishes - AsyncThrowingJustSequence: Creates an
AsyncSequencethat emits an elements and finishes bases on a throwing closure - AsyncLazySequence: Creates an
AsyncSequenceof the elements from the base sequence - AsyncTimerSequence: Creates an
AsyncSequencethat emits a date value periodically - AsyncStream Pipe: Creates an AsyncStream and returns a tuple standing for its inputs and outputs
Operators
handleEvents(): Executes closures during the lifecycle of the selfmapToResult(): Maps elements and failure from self to aResulttypeprepend(_:): Prepends an element to selfscan(::): Transforms elements from self by providing the current element to a closure along with the last value returned by the closureassign(_:): Assigns elements from self to a propertycollect(_:): Iterate over elements from self and execute a closureeraseToAnyAsyncSequence(): Erases to AnyAsyncSequenceflatMapLatest(_:): Transforms elements from self into aAsyncSequenceand republishes elements sent by the most recently receivedAsyncSequencewhen self is anAsyncSequenceofAsyncSequencemulticast(_:): Shares values from self to several consumers thanks to a provided Subjectshare(): Shares values from self to several consumersswitchToLatest(): Republishes elements sent by the most recently receivedAsyncSequencewhen self is anAsyncSequenceofAsyncSequence
More operators and extensions are to come. Pull requests are of course welcome.
Package Metadata
Repository: sideeffect-io/asyncextensions
Default branch: main
README: README.md