@@ -734,10 +734,10 @@ strategies.
734
734
735
735
## Alternatives considered
736
736
737
- ### Provide the ` onTermination ` callback to the factory method
737
+ ### Provide an ` onTermination ` callback to the factory method
738
738
739
739
During development of the new APIs, I first tried to provide the ` onTermination `
740
- callback in the ` makeStream ` method. However, that showed significant usability
740
+ callback in the ` makeChannel ` method. However, that showed significant usability
741
741
problems in scenarios where one wants to store the source in a type and
742
742
reference ` self ` in the ` onTermination ` closure at the same time; hence, I kept
743
743
the current pattern of setting the ` onTermination ` closure on the source.
@@ -746,12 +746,12 @@ the current pattern of setting the `onTermination` closure on the source.
746
746
747
747
During the pitch phase, it was raised that we should provide a
748
748
` onConsumerCancellation ` callback which gets invoked once the asynchronous
749
- stream notices that the consuming task got cancelled. This callback could be
750
- used to customize how cancellation is handled by the stream e.g. one could
751
- imagine writing a few more elements to the stream before finishing it. Right now
752
- the stream immediately returns ` nil ` or throws a ` CancellationError ` when it
749
+ channel notices that the consuming task got cancelled. This callback could be
750
+ used to customize how cancellation is handled by the channel e.g. one could
751
+ imagine writing a few more elements to the channel before finishing it. Right now
752
+ the channel immediately returns ` nil ` or throws a ` CancellationError ` when it
753
753
notices cancellation. This proposal decided to not provide this customization
754
- because it opens up the possiblity that asynchronous streams are not terminating
754
+ because it opens up the possiblity that asynchronous channels are not terminating
755
755
when implemented incorrectly. Additionally, asynchronous sequences are not the
756
756
only place where task cancellation leads to an immediate error being thrown i.e.
757
757
` Task.sleep() ` does the same. Hence, the value of the asynchronous not
@@ -762,30 +762,19 @@ the future and we can just default it to the current behaviour.
762
762
### Create a custom type for the ` Result ` of the ` onProduceMore ` callback
763
763
764
764
The ` onProducerMore ` callback takes a ` Result<Void, Error> ` which is used to
765
- indicate if the producer should produce more or if the asynchronous stream
765
+ indicate if the producer should produce more or if the asynchronous channel
766
766
finished. We could introduce a new type for this but the proposal decided
767
767
against it since it effectively is a result type.
768
768
769
769
### Use an initializer instead of factory methods
770
770
771
- Instead of providing a ` makeStream ` factory method we could use an initializer
771
+ Instead of providing a ` makeChannel ` factory method we could use an initializer
772
772
approach that takes a closure which gets the ` Source ` passed into. A similar API
773
773
has been offered with the ` Continuation ` based approach and
774
774
[ SE-0388] ( https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md )
775
775
introduced new factory methods to solve some of the usability ergonomics with
776
776
the initializer based APIs.
777
777
778
- ### Follow the ` AsyncStream ` & ` AsyncThrowingStream ` naming
779
-
780
- All other types that offer throwing and non-throwing variants are currently
781
- following the naming scheme where the throwing variant gets an extra ` Throwing `
782
- in its name. Now that Swift is gaining typed throws support this would make the
783
- type with the ` Failure ` parameter capable to express both throwing and
784
- non-throwing variants. However, the less flexible type has the better name.
785
- Hence, this proposal uses the good name for the throwing variant with the
786
- potential in the future to deprecate the ` AsyncNonThrowingBackpressuredStream `
787
- in favour of adopting typed throws.
788
-
789
778
## Acknowledgements
790
779
791
780
- [ Johannes Weiss] ( https://github.com/weissi ) - For making me aware how
0 commit comments