-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/async support #31
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
Open
arducumutcan
wants to merge
19
commits into
develop
Choose a base branch
from
feature/async-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4213128
Async Await support for data tasks.
Rashidium ee32c5b
Fixed crash and unit test. Refactoring async methods
arducumutcan 02bfd79
Refactor async unit tests methods
arducumutcan 7ab0b46
Optimize for loop duration
arducumutcan 2bfcdb5
Merge branch 'develop' into feature/async-support
Rashidium 1281fe7
Add todo for task queue bug? (maybe)
Rashidium 706fc69
Add todo async support for url session pinning delegate.
Rashidium 551efcf
Update NetworkingTests.swift
Rashidium 6eb9f48
Separated URLSessingPinningDelegate into async and legacy and refacto…
arducumutcan a61ae4c
Removed unused codes and fixed unit test.
arducumutcan 7be5feb
Swiftformat changes.
arducumutcan 0b2b460
Swiftformatted.
Rashidium 733d1eb
Removed TODO comments. Improved code quality in the urlSession didRec…
arducumutcan 346b0ee
Refactor delegate creation to use composer
arducumutcan c6e4fc5
Refactoring requestData function
arducumutcan 7ee8f18
Unit test fix and added todo task-async flow
arducumutcan 6077af2
Update Networkable+DataTaskAsync.swift
Rashidium 083d633
Swiftformatted.
Rashidium 4f31f36
Remove Legacy keyword from clousere based netwroking files.
Rashidium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // | ||
| // Networkable+DataTaskAsync.swift | ||
| // Network | ||
| // | ||
| // Created by Rasid Ramazanov on 25.11.2019. | ||
| // Copyright © 2019 LeanScale. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
| import MBErrorKit | ||
|
|
||
| /// Networkable extension related to data tasks. | ||
| /// | ||
| @available(iOS 13.0.0, *) extension Networkable { | ||
| /// Fetch data with specified parameters and return back with the completion. | ||
| /// - Parameters: | ||
| /// - type: Type of the result. | ||
| /// - Returns: Response as `Result` | ||
| public func fetch<V: Decodable>(_ type: V.Type) async throws -> V { | ||
| try await fetch(request) | ||
| } | ||
|
|
||
| private func fetch<V: Decodable>(_ urlRequest: URLRequest) async throws -> V { | ||
| let (response, data, error) = await requestData(urlRequest) | ||
|
|
||
| if let error, | ||
| isNetworkConnectionError((error as NSError).code) { | ||
| let error = MBErrorKit.NetworkingError.networkConnectionError(error) | ||
| MBErrorKit.ErrorKit.shared().delegate?.errorKitDidCatch(networkingError: error) | ||
| printErrorLog(error) | ||
| throw error | ||
|
|
||
| } else if let error { | ||
| let networkingError: NetworkingError = if (error as NSError).code == NSURLErrorCancelled { | ||
| .dataTaskCancelled | ||
| } else { | ||
| MBErrorKit.NetworkingError.underlyingError(error, response, data) | ||
| } | ||
| MBErrorKit.ErrorKit.shared().delegate?.errorKitDidCatch(networkingError: networkingError) | ||
| printErrorLog(networkingError) | ||
| throw networkingError | ||
|
|
||
| } else if let httpResponse = response as? HTTPURLResponse, | ||
| isSuccess(httpResponse.statusCode) { | ||
| let error = MBErrorKit.NetworkingError.httpError(error, httpResponse, data) | ||
| MBErrorKit.ErrorKit.shared().delegate?.errorKitDidCatch(networkingError: error) | ||
| printErrorLog(error) | ||
| throw error | ||
|
|
||
| } else if let response, data == nil || data?.count == 0 { | ||
| let error = MBErrorKit.NetworkingError.dataTaskError(response, data) | ||
| MBErrorKit.ErrorKit.shared().delegate?.errorKitDidCatch(networkingError: error) | ||
| printErrorLog(error) | ||
| throw error | ||
|
|
||
| } else if let data, data.count > 0 { | ||
| do { | ||
| // If requested decodable type is Data, received data will be returned. | ||
| if V.Type.self == Data.Type.self { | ||
| return data as! V | ||
| } | ||
| let decodableData = try JSONDecoder().decode(V.self, from: data) | ||
| return decodableData | ||
| } catch let sError { | ||
| let error = MBErrorKit.NetworkingError.decodingError(sError, response, data) | ||
| MBErrorKit.ErrorKit.shared().delegate?.errorKitDidCatch(serializationError: error) | ||
| self.printErrorLog(error) | ||
| throw error | ||
| } | ||
|
|
||
| } else { | ||
| let error = MBErrorKit.NetworkingError.unkownError(error, data) | ||
| MBErrorKit.ErrorKit.shared().delegate?.errorKitDidCatch(networkingError: error) | ||
| printErrorLog(error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| private func requestData(_ urlRequest: URLRequest) async -> (URLResponse?, Data?, Error?) { | ||
| // TODO: Should async support Session.shared.taskInProgress cancellation logic? | ||
|
|
||
| do { | ||
| let (data, response) = try await Session.shared.session.data(for: urlRequest) | ||
| printResponse(data) | ||
| return (response, data, nil) | ||
| } catch { | ||
| return (nil, nil, error) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rashidium burada şu kodu kullanamaz mıyız abi?
kendim ufak bir uygulama yaptım. Pulse ile dinleyebiliyorum şuan network u
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yapılabilir Eser ama with checked continuation tam olarak async desteği getiriyor mu emin değilim. http://github.com/mobven/binbin-ios 'taki networkü incelemeni tavsiye ederim. eğer test'lerimizi geçerse ordaki yapıyı yeni altyapımız yapacağız.