Skip to content

Commit

Permalink
Twitter dont block main on file ops (#7298)
Browse files Browse the repository at this point in the history
* Remove sync wait on filesystem from main queue

On initialization, a promise is created that synchronously
waits on an NSOperationQueue with file ops in it. Re-work
this so that the promise is asynchronously fulfilled with
an operation that is inserted into the queue, and then
dispatched back to the main queue when finished.
  • Loading branch information
jhollida24 authored Jan 21, 2021
1 parent 199ef50 commit 3ca9dca
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Crashlytics/Crashlytics/Controllers/FIRCLSReportManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,18 @@ - (FBLPromise *)deleteUnsentReports {
NSOperationQueue *__weak queue = _operationQueue;
FBLPromise *__weak unsentReportsHandled = _unsentReportsHandled;
promise = [promise then:^id _Nullable(NSNumber *_Nullable value) {
[queue waitUntilAllOperationsAreFinished];
// Signal that to callers of processReports that everything is finished.
[unsentReportsHandled fulfill:nil];
return value;
FBLPromise *allOpsFinished = [FBLPromise pendingPromise];
[queue addOperationWithBlock:^{
[allOpsFinished fulfill:nil];
}];

return [allOpsFinished onQueue:dispatch_get_main_queue()
then:^id _Nullable(id _Nullable allOpsFinishedValue) {
// Signal that to callers of processReports that everything is
// finished.
[unsentReportsHandled fulfill:nil];
return value;
}];
}];

return promise;
Expand Down

0 comments on commit 3ca9dca

Please sign in to comment.