Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy channels for public iterate() on internal queue. #919

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ARTChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
- (ChannelType)get:(NSString *)name;
- (ChannelType)get:(NSString *)name options:(ARTChannelOptions *)options;
- (void)release:(NSString *)name;
- (id<NSFastEnumeration>)iterate;
- (id<NSFastEnumeration>)copyIntoIteratorWithMapper:(id (^)(ChannelType))mapper;
QuintinWillison marked this conversation as resolved.
Show resolved Hide resolved

@end
8 changes: 6 additions & 2 deletions Source/ARTChannels.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ - (instancetype)initWithDelegate:(id)delegate dispatchQueue:(dispatch_queue_t)qu
return self;
}

- (id<NSFastEnumeration>)iterate {
- (id<NSFastEnumeration>)copyIntoIteratorWithMapper:(id (^)(id))mapper {
__block id<NSFastEnumeration>ret;
dispatch_sync(_queue, ^{
ret = [self getNosyncIterable];
NSMutableArray *channels = [[NSMutableArray alloc] init];
for (id internalChannel in [self getNosyncIterable]) {
[channels addObject:mapper(internalChannel)];
}
ret = [channels objectEnumerator];
});
return ret;
}
Expand Down
1 change: 1 addition & 0 deletions Source/ARTRealtimeChannels+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN

- (ARTRealtimeChannelInternal *)get:(NSString *)name;
- (ARTRealtimeChannelInternal *)get:(NSString *)name options:(ARTChannelOptions *)options;
- (id<NSFastEnumeration>)copyIntoIteratorWithMapper:(ARTRealtimeChannel *(^)(ARTRealtimeChannelInternal *))mapper;

- (instancetype)initWithRealtime:(ARTRealtimeInternal *)realtime;

Expand Down
2 changes: 1 addition & 1 deletion Source/ARTRealtimeChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)exists:(NSString *)name;
- (void)release:(NSString *)name callback:(nullable void (^)(ARTErrorInfo *_Nullable))errorInfo;
- (void)release:(NSString *)name;
- (id<NSFastEnumeration>)iterate;

@end

@interface ARTRealtimeChannels : NSObject<ARTRealtimeChannelsProtocol>

- (ARTRealtimeChannel *)get:(NSString *)name;
- (ARTRealtimeChannel *)get:(NSString *)name options:(ARTChannelOptions *)options;
- (id<NSFastEnumeration>)iterate;

@end

Expand Down
12 changes: 5 additions & 7 deletions Source/ARTRealtimeChannels.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ - (void)release:(NSString *)name {
}

- (id<NSFastEnumeration>)iterate {
NSMutableArray *channels = [[NSMutableArray alloc] init];
for (ARTRealtimeChannelInternal *internalChannel in [_internal iterate]) {
[channels addObject:[[ARTRealtimeChannel alloc] initWithInternal:internalChannel queuedDealloc:_dealloc]];
}
return channels;
return [_internal copyIntoIteratorWithMapper:^ARTRealtimeChannel *(ARTRealtimeChannelInternal *internalChannel) {
return [[ARTRealtimeChannel alloc] initWithInternal:internalChannel queuedDealloc:self->_dealloc];
}];
}

@end
Expand Down Expand Up @@ -86,8 +84,8 @@ - (id)makeChannel:(NSString *)name options:(ARTChannelOptions *)options {
return [ARTRealtimeChannelInternal channelWithRealtime:_realtime andName:name withOptions:options];
}

- (id<NSFastEnumeration>)iterate {
return [_channels iterate];
- (id<NSFastEnumeration>)copyIntoIteratorWithMapper:(ARTRealtimeChannel *(^)(ARTRealtimeChannelInternal *))mapper {
return [_channels copyIntoIteratorWithMapper:mapper];
}

- (ARTRealtimeChannelInternal *)get:(NSString *)name {
Expand Down
1 change: 1 addition & 0 deletions Source/ARTRestChannels+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN

- (ARTRestChannelInternal *)get:(NSString *)name;
- (ARTRestChannelInternal *)get:(NSString *)name options:(ARTChannelOptions *)options;
- (id<NSFastEnumeration>)copyIntoIteratorWithMapper:(ARTRestChannel *(^)(ARTRestChannelInternal *))mapper;

- (instancetype)initWithRest:(ARTRestInternal *)rest;
- (ARTRestChannelInternal *)_getChannel:(NSString *)name options:(ARTChannelOptions * _Nullable)options addPrefix:(BOOL)addPrefix;
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTRestChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ NS_ASSUME_NONNULL_BEGIN
// Thus, we can't make ARTRestChannels inherit from ARTChannels; we have to compose them instead.
- (BOOL)exists:(NSString *)name;
- (void)release:(NSString *)name;
- (id<NSFastEnumeration>)iterate;

@end

@interface ARTRestChannels : NSObject<ARTRestChannelsProtocol>

- (ARTRestChannel *)get:(NSString *)name;
- (ARTRestChannel *)get:(NSString *)name options:(ARTChannelOptions *)options;
- (id<NSFastEnumeration>)iterate;

@end

Expand Down
12 changes: 5 additions & 7 deletions Source/ARTRestChannels.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ - (void)release:(NSString *)name {
}

- (id<NSFastEnumeration>)iterate {
NSMutableArray *channels = [[NSMutableArray alloc] init];
for (ARTRestChannelInternal *internalChannel in [_internal iterate]) {
[channels addObject:[[ARTRestChannel alloc] initWithInternal:internalChannel queuedDealloc:_dealloc]];
}
return channels;
return [_internal copyIntoIteratorWithMapper:^ARTRestChannel *(ARTRestChannelInternal *internalChannel) {
return [[ARTRestChannel alloc] initWithInternal:internalChannel queuedDealloc:self->_dealloc];
}];
}

@end
Expand Down Expand Up @@ -80,9 +78,9 @@ - (id)makeChannel:(NSString *)name options:(ARTChannelOptions *)options {
} ART_TRY_OR_REPORT_CRASH_END
}

- (id<NSFastEnumeration>)iterate {
- (id<NSFastEnumeration>)copyIntoIteratorWithMapper:(ARTRestChannel *(^)(ARTRestChannelInternal *))mapper {
ART_TRY_OR_REPORT_CRASH_START(_rest) {
return [_channels iterate];
return [_channels copyIntoIteratorWithMapper:mapper];
} ART_TRY_OR_REPORT_CRASH_END
}

Expand Down