Skip to content

feat: runInBackground thread for iOS - #39

Merged
zamotany merged 2 commits into
v2from
feat/background-thread-ios
May 31, 2021
Merged

feat: runInBackground thread for iOS#39
zamotany merged 2 commits into
v2from
feat/background-thread-ios

Conversation

@deorst

@deorst deorst commented May 31, 2021

Copy link
Copy Markdown
Contributor

Summary

Added method runInBackground which lets to run methods loadChunk, preloadChunk and invalidateChunks without blocking the UI thread for iOS.

Test plan

Manually test TesterApp using 2s delay in methods loadChunk, preloadChunk and invalidateChunks.
The app is responsive hence UI thread is not blocked.

ios.720.mov

@deorst
deorst requested a review from zamotany May 31, 2021 13:27
Comment thread ios/ChunkManager.mm Outdated
Comment on lines +68 to +85
[self runInBackground:^(){
if (!fetch) {
// Do nothing, chunk is already preloaded
resolve(nil);
} else {
reject(UnsupportedScheme,
[NSString stringWithFormat:@"Scheme in URL '%@' is not supported", chunkUrlString], nil);
NSURL *chunkUrl = [NSURL URLWithString:chunkUrlString];
if ([[chunkUrl scheme] hasPrefix:@"http"]) {
[self downloadAndCache:chunkId chunkUrl:chunkUrl completionHandler:^(NSError *error) {
if (error) {
reject(ChunkDownloadFailure, error.localizedFailureReason, nil);
} else {
resolve(nil);
}
}];
} else {
reject(UnsupportedScheme,
[NSString stringWithFormat:@"Scheme in URL '%@' is not supported", chunkUrlString], nil);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sugget to change it to:

if (!fetch) {
  // Do nothing, chunk is already preloaded
  resolve(nil);
} else {
  [self runInBackground:^() {
    ...
  }];
}

To avoid unnecessarily spawning new threads.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@zamotany
zamotany merged commit edcfdb9 into v2 May 31, 2021
@zamotany
zamotany deleted the feat/background-thread-ios branch May 31, 2021 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants