Skip to content

Commit 293806b

Browse files
committedJul 17, 2024
Added @mainactor to SharedSequence, Driver and Signal functions taking closure arguments.
1 parent 6491a16 commit 293806b

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed
 

‎RxCocoa/Traits/Driver/Driver+Subscription.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingSt
155155
gracefully completed, errored, or if the generation is canceled by disposing subscription)
156156
- returns: Subscription object used to unsubscribe from the observable sequence.
157157
*/
158+
@preconcurrency @MainActor
158159
public func drive<Object: AnyObject>(
159160
with object: Object,
160-
onNext: ((Object, Element) -> Void)? = nil,
161-
onCompleted: ((Object) -> Void)? = nil,
161+
onNext: (@MainActor (Object, Element) -> Void)? = nil,
162+
onCompleted: (@MainActor (Object) -> Void)? = nil,
162163
onDisposed: ((Object) -> Void)? = nil
163164
) -> Disposable {
164165
MainScheduler.ensureRunningOnMainThread(errorMessage: errorMessage)
@@ -178,9 +179,10 @@ extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingSt
178179
gracefully completed, errored, or if the generation is canceled by disposing subscription)
179180
- returns: Subscription object used to unsubscribe from the observable sequence.
180181
*/
182+
@preconcurrency @MainActor
181183
public func drive(
182-
onNext: ((Element) -> Void)? = nil,
183-
onCompleted: (() -> Void)? = nil,
184+
onNext: (@MainActor (Element) -> Void)? = nil,
185+
onCompleted: (@MainActor () -> Void)? = nil,
184186
onDisposed: (() -> Void)? = nil
185187
) -> Disposable {
186188
MainScheduler.ensureRunningOnMainThread(errorMessage: errorMessage)

‎RxCocoa/Traits/SharedSequence/SharedSequence+Operators.swift

+30-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extension SharedSequenceConvertibleType {
1717
- parameter selector: A transform function to apply to each source element.
1818
- returns: An observable sequence whose elements are the result of invoking the transform function on each element of source.
1919
*/
20-
public func map<Result>(_ selector: @escaping (Element) -> Result) -> SharedSequence<SharingStrategy, Result> {
20+
@preconcurrency @MainActor
21+
public func map<Result>(_ selector: @escaping @MainActor (Element) -> Result) -> SharedSequence<SharingStrategy, Result> {
2122
let source = self
2223
.asObservable()
2324
.map(selector)
@@ -35,7 +36,8 @@ extension SharedSequenceConvertibleType {
3536
- returns: An observable sequence whose elements are the result of filtering the transform function for each element of the source.
3637

3738
*/
38-
public func compactMap<Result>(_ selector: @escaping (Element) -> Result?) -> SharedSequence<SharingStrategy, Result> {
39+
@preconcurrency @MainActor
40+
public func compactMap<Result>(_ selector: @escaping @MainActor (Element) -> Result?) -> SharedSequence<SharingStrategy, Result> {
3941
let source = self
4042
.asObservable()
4143
.compactMap(selector)
@@ -51,7 +53,8 @@ extension SharedSequenceConvertibleType {
5153
- parameter predicate: A function to test each source element for a condition.
5254
- returns: An observable sequence that contains elements from the input sequence that satisfy the condition.
5355
*/
54-
public func filter(_ predicate: @escaping (Element) -> Bool) -> SharedSequence<SharingStrategy, Element> {
56+
@preconcurrency @MainActor
57+
public func filter(_ predicate: @escaping @MainActor (Element) -> Bool) -> SharedSequence<SharingStrategy, Element> {
5558
let source = self
5659
.asObservable()
5760
.filter(predicate)
@@ -92,7 +95,8 @@ extension SharedSequenceConvertibleType {
9295
- returns: An observable sequence whose elements are the result of invoking the transform function on each element of source producing an
9396
Observable of Observable sequences and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
9497
*/
95-
public func flatMapLatest<Sharing, Result>(_ selector: @escaping (Element) -> SharedSequence<Sharing, Result>)
98+
@preconcurrency @MainActor
99+
public func flatMapLatest<Sharing, Result>(_ selector: @escaping @MainActor (Element) -> SharedSequence<Sharing, Result>)
96100
-> SharedSequence<Sharing, Result> {
97101
let source: Observable<Result> = self
98102
.asObservable()
@@ -111,7 +115,8 @@ extension SharedSequenceConvertibleType {
111115
- parameter selector: A transform function to apply to element that was observed while no observable is executing in parallel.
112116
- returns: An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence that was received while no other sequence was being calculated.
113117
*/
114-
public func flatMapFirst<Sharing, Result>(_ selector: @escaping (Element) -> SharedSequence<Sharing, Result>)
118+
@preconcurrency @MainActor
119+
public func flatMapFirst<Sharing, Result>(_ selector: @escaping @MainActor (Element) -> SharedSequence<Sharing, Result>)
115120
-> SharedSequence<Sharing, Result> {
116121
let source: Observable<Result> = self
117122
.asObservable()
@@ -134,7 +139,8 @@ extension SharedSequenceConvertibleType {
134139
- parameter onDispose: Action to invoke after subscription to source observable has been disposed for any reason. It can be either because sequence terminates for some reason or observer subscription being disposed.
135140
- returns: The source sequence with the side-effecting behavior applied.
136141
*/
137-
public func `do`(onNext: ((Element) -> Void)? = nil, afterNext: ((Element) -> Void)? = nil, onCompleted: (() -> Void)? = nil, afterCompleted: (() -> Void)? = nil, onSubscribe: (() -> Void)? = nil, onSubscribed: (() -> Void)? = nil, onDispose: (() -> Void)? = nil)
142+
@preconcurrency @MainActor
143+
public func `do`(onNext: (@MainActor (Element) -> Void)? = nil, afterNext: (@MainActor (Element) -> Void)? = nil, onCompleted: (@MainActor () -> Void)? = nil, afterCompleted: ( @MainActor () -> Void)? = nil, onSubscribe: (@MainActor () -> Void)? = nil, onSubscribed: (@MainActor () -> Void)? = nil, onDispose: (() -> Void)? = nil)
138144
-> SharedSequence<SharingStrategy, Element> {
139145
let source = self.asObservable()
140146
.do(onNext: onNext, afterNext: afterNext, onCompleted: onCompleted, afterCompleted: afterCompleted, onSubscribe: onSubscribe, onSubscribed: onSubscribed, onDispose: onDispose)
@@ -184,7 +190,8 @@ extension SharedSequenceConvertibleType {
184190
- parameter keySelector: A function to compute the comparison key for each element.
185191
- returns: An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
186192
*/
187-
public func distinctUntilChanged<Key: Equatable>(_ keySelector: @escaping (Element) -> Key) -> SharedSequence<SharingStrategy, Element> {
193+
@preconcurrency @MainActor
194+
public func distinctUntilChanged<Key: Equatable>(_ keySelector: @escaping @MainActor (Element) -> Key) -> SharedSequence<SharingStrategy, Element> {
188195
let source = self.asObservable()
189196
.distinctUntilChanged(keySelector, comparer: { $0 == $1 })
190197
return SharedSequence(source)
@@ -196,7 +203,8 @@ extension SharedSequenceConvertibleType {
196203
- parameter comparer: Equality comparer for computed key values.
197204
- returns: An observable sequence only containing the distinct contiguous elements, based on `comparer`, from the source sequence.
198205
*/
199-
public func distinctUntilChanged(_ comparer: @escaping (Element, Element) -> Bool) -> SharedSequence<SharingStrategy, Element> {
206+
@preconcurrency @MainActor
207+
public func distinctUntilChanged(_ comparer: @escaping @MainActor (Element, Element) -> Bool) -> SharedSequence<SharingStrategy, Element> {
200208
let source = self.asObservable()
201209
.distinctUntilChanged({ $0 }, comparer: comparer)
202210
return SharedSequence<SharingStrategy, Element>(source)
@@ -209,7 +217,8 @@ extension SharedSequenceConvertibleType {
209217
- parameter comparer: Equality comparer for computed key values.
210218
- returns: An observable sequence only containing the distinct contiguous elements, based on a computed key value and the comparer, from the source sequence.
211219
*/
212-
public func distinctUntilChanged<K>(_ keySelector: @escaping (Element) -> K, comparer: @escaping (K, K) -> Bool) -> SharedSequence<SharingStrategy, Element> {
220+
@preconcurrency @MainActor
221+
public func distinctUntilChanged<K>(_ keySelector: @escaping @MainActor (Element) -> K, comparer: @escaping (K, K) -> Bool) -> SharedSequence<SharingStrategy, Element> {
213222
let source = self.asObservable()
214223
.distinctUntilChanged(keySelector, comparer: comparer)
215224
return SharedSequence<SharingStrategy, Element>(source)
@@ -226,7 +235,8 @@ extension SharedSequenceConvertibleType {
226235
- parameter selector: A transform function to apply to each element.
227236
- returns: An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.
228237
*/
229-
public func flatMap<Sharing, Result>(_ selector: @escaping (Element) -> SharedSequence<Sharing, Result>) -> SharedSequence<Sharing, Result> {
238+
@preconcurrency @MainActor
239+
public func flatMap<Sharing, Result>(_ selector: @escaping @MainActor (Element) -> SharedSequence<Sharing, Result>) -> SharedSequence<Sharing, Result> {
230240
let source = self.asObservable()
231241
.flatMap(selector)
232242

@@ -355,7 +365,8 @@ extension SharedSequenceConvertibleType {
355365
- parameter accumulator: An accumulator function to be invoked on each element.
356366
- returns: An observable sequence containing the accumulated values.
357367
*/
358-
public func scan<A>(_ seed: A, accumulator: @escaping (A, Element) -> A)
368+
@preconcurrency @MainActor
369+
public func scan<A>(_ seed: A, accumulator: @escaping @MainActor (A, Element) -> A)
359370
-> SharedSequence<SharingStrategy, A> {
360371
let source = self.asObservable()
361372
.scan(seed, accumulator: accumulator)
@@ -398,7 +409,8 @@ extension SharedSequence {
398409
- parameter resultSelector: Function to invoke for each series of elements at corresponding indexes in the sources.
399410
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
400411
*/
401-
public static func zip<Collection: Swift.Collection, Result>(_ collection: Collection, resultSelector: @escaping ([Element]) throws -> Result) -> SharedSequence<SharingStrategy, Result>
412+
@preconcurrency @MainActor
413+
public static func zip<Collection: Swift.Collection, Result>(_ collection: Collection, resultSelector: @escaping @MainActor ([Element]) throws -> Result) -> SharedSequence<SharingStrategy, Result>
402414
where Collection.Element == SharedSequence<SharingStrategy, Element> {
403415
let source = Observable.zip(collection.map { $0.asSharedSequence().asObservable() }, resultSelector: resultSelector)
404416
return SharedSequence<SharingStrategy, Result>(source)
@@ -425,7 +437,8 @@ extension SharedSequence {
425437
- parameter resultSelector: Function to invoke whenever any of the sources produces an element.
426438
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
427439
*/
428-
public static func combineLatest<Collection: Swift.Collection, Result>(_ collection: Collection, resultSelector: @escaping ([Element]) throws -> Result) -> SharedSequence<SharingStrategy, Result>
440+
@preconcurrency @MainActor
441+
public static func combineLatest<Collection: Swift.Collection, Result>(_ collection: Collection, resultSelector: @escaping @MainActor ([Element]) throws -> Result) -> SharedSequence<SharingStrategy, Result>
429442
where Collection.Element == SharedSequence<SharingStrategy, Element> {
430443
let source = Observable.combineLatest(collection.map { $0.asObservable() }, resultSelector: resultSelector)
431444
return SharedSequence<SharingStrategy, Result>(source)
@@ -456,9 +469,10 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
456469
- parameter resultSelector: A function to combine the unretained referenced on `obj` and the value of the observable sequence.
457470
- returns: An observable sequence that contains the result of `resultSelector` being called with an unretained reference on `obj` and the values of the original sequence.
458471
*/
472+
@preconcurrency @MainActor
459473
public func withUnretained<Object: AnyObject, Out>(
460474
_ obj: Object,
461-
resultSelector: @escaping (Object, Element) -> Out
475+
resultSelector: @escaping @MainActor (Object, Element) -> Out
462476
) -> SharedSequence<SharingStrategy, Out> {
463477
SharedSequence(self.asObservable().withUnretained(obj, resultSelector: resultSelector))
464478
}
@@ -503,7 +517,8 @@ extension SharedSequenceConvertibleType {
503517
- parameter resultSelector: Function to invoke for each element from the self combined with the latest element from the second source, if any.
504518
- returns: An observable sequence containing the result of combining each element of the self with the latest element from the second source, if any, using the specified result selector function.
505519
*/
506-
public func withLatestFrom<SecondO: SharedSequenceConvertibleType, ResultType>(_ second: SecondO, resultSelector: @escaping (Element, SecondO.Element) -> ResultType) -> SharedSequence<SharingStrategy, ResultType> where SecondO.SharingStrategy == SharingStrategy {
520+
@preconcurrency @MainActor
521+
public func withLatestFrom<SecondO: SharedSequenceConvertibleType, ResultType>(_ second: SecondO, resultSelector: @escaping @MainActor (Element, SecondO.Element) -> ResultType) -> SharedSequence<SharingStrategy, ResultType> where SecondO.SharingStrategy == SharingStrategy {
507522
let source = self.asObservable()
508523
.withLatestFrom(second.asSharedSequence(), resultSelector: resultSelector)
509524

‎RxCocoa/Traits/Signal/Signal+Subscription.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
130130
gracefully completed, errored, or if the generation is canceled by disposing subscription)
131131
- returns: Subscription object used to unsubscribe from the observable sequence.
132132
*/
133+
@preconcurrency @MainActor
133134
public func emit<Object: AnyObject>(
134135
with object: Object,
135-
onNext: ((Object, Element) -> Void)? = nil,
136-
onCompleted: ((Object) -> Void)? = nil,
136+
onNext: (@MainActor (Object, Element) -> Void)? = nil,
137+
onCompleted: (@MainActor (Object) -> Void)? = nil,
137138
onDisposed: ((Object) -> Void)? = nil
138139
) -> Disposable {
139140
self.asObservable().subscribe(
@@ -156,9 +157,10 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
156157
gracefully completed, errored, or if the generation is canceled by disposing subscription)
157158
- returns: Subscription object used to unsubscribe from the observable sequence.
158159
*/
160+
@preconcurrency @MainActor
159161
public func emit(
160-
onNext: ((Element) -> Void)? = nil,
161-
onCompleted: (() -> Void)? = nil,
162+
onNext: (@MainActor (Element) -> Void)? = nil,
163+
onCompleted: (@MainActor () -> Void)? = nil,
162164
onDisposed: (() -> Void)? = nil
163165
) -> Disposable {
164166
self.asObservable().subscribe(onNext: onNext, onCompleted: onCompleted, onDisposed: onDisposed)

0 commit comments

Comments
 (0)