
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
60 lines
1.4 KiB
Objective-C
60 lines
1.4 KiB
Objective-C
#import "RoomBoomEventQueue.h"
|
|
#import "RoomBoomEvent.h"
|
|
|
|
@implementation RoomBoomEventQueue
|
|
|
|
- (instancetype)init {
|
|
self = [super init];
|
|
if (self) {
|
|
_events = [[NSMutableArray alloc] init];
|
|
_isProcessing = NO;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)enqueueEvent:(id)event {
|
|
@synchronized (self.events) {
|
|
[self.events addObject:event];
|
|
|
|
// 如果当前没有在处理事件,则开始处理
|
|
if (!self.isProcessing) {
|
|
[self processNextEvent];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)processNextEvent {
|
|
@synchronized (self.events) {
|
|
if (self.events.count == 0) {
|
|
self.isProcessing = NO;
|
|
return;
|
|
}
|
|
|
|
self.isProcessing = YES;
|
|
id event = self.events.firstObject;
|
|
[self.events removeObjectAtIndex:0];
|
|
|
|
if (self.processBlock) {
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
self.processBlock(event);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)clear {
|
|
@synchronized (self.events) {
|
|
[self.events removeAllObjects];
|
|
self.isProcessing = NO;
|
|
}
|
|
}
|
|
|
|
- (NSString *)description {
|
|
return [NSString stringWithFormat:@"<%@: %p> events count: %lu, isProcessing: %@",
|
|
NSStringFromClass([self class]),
|
|
self,
|
|
(unsigned long)self.events.count,
|
|
self.isProcessing ? @"YES" : @"NO"];
|
|
}
|
|
|
|
@end |