@@ -60,15 +60,16 @@ - (void)presentDialogWithTitle:(NSString * _Nonnull)title withMessage:(NSString
6060 // ensure this UI code executes on the main thread
6161 dispatch_async (dispatch_get_main_queue (), ^{
6262 let request = [[OSDialogRequest alloc ] initWithTitle: title withMessage: message withActionTitles: actionTitles withCancelTitle: cancelTitle withCompletion: completion];
63-
64- [self .queue addObject: request];
65-
66- // check if already presenting a different dialog
67- // if so, we shouldn't present on top of existing dialog
68- if (self.queue .count > 1 )
69- return ;
70-
71- [self displayDialog: request];
63+ @synchronized (self.queue ) {
64+ [self .queue addObject: request];
65+
66+ // check if already presenting a different dialog
67+ // if so, we shouldn't present on top of existing dialog
68+ if (self.queue .count > 1 )
69+ return ;
70+
71+ [self displayDialog: request];
72+ }
7273 });
7374}
7475
@@ -101,23 +102,28 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto
101102
102103- (void )delayResult : (int )result {
103104 dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
104- let currentDialog = self.queue .firstObject ;
105-
106- if (currentDialog.completion )
107- currentDialog.completion (result);
108-
109- [self .queue removeObjectAtIndex: 0 ];
110-
111- // check if no more dialogs left to display in queue
112- if (self.queue .count == 0 )
113- return ;
114-
115- let nextDialog = self.queue .firstObject ;
116-
117- [self displayDialog: nextDialog];
105+ @synchronized (self.queue ) {
106+ if (self.queue .count > 0 ) {
107+ let currentDialog = self.queue .firstObject ;
108+
109+ if (currentDialog.completion )
110+ currentDialog.completion (result);
111+
112+ [self .queue removeObjectAtIndex: 0 ];
113+ }
114+
115+ // check if no more dialogs left to display in queue
116+ if (self.queue .count == 0 )
117+ return ;
118+
119+ let nextDialog = self.queue .firstObject ;
120+
121+ [self displayDialog: nextDialog];
122+ }
118123 });
119124}
120125
126+ // Unused. Currently only referenced in player model unit tests
121127- (void )clearQueue {
122128 self.queue = [NSMutableArray new ];
123129}
0 commit comments