-
Notifications
You must be signed in to change notification settings - Fork 1
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
[feat] Concurrency improvements #52
base: dev
Are you sure you want to change the base?
Changes from all commits
a55d385
06a9819
641bc10
ca85c82
fbaa27b
71f2a19
196b8f7
7ba3e6b
b8a20bc
155dbb1
e617286
7ca81c7
78b039f
4107039
410f39f
bd75c8d
82c53a3
f75e1ed
644e5e4
8bdffbe
9e72630
d385d34
3386b03
5bde238
bde749f
41ecd24
fb2fc95
9febe71
1effc96
ab9ebcc
2312444
f2bff45
9dd468a
24b7b30
f54eb2b
2590c04
3481616
c45f120
dee8532
9645825
296c372
987d49d
d6613e0
0b170b4
7b8c5df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "collectionconcurrencykit", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git", | ||
"state" : { | ||
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95", | ||
"version" : "0.2.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "cryptoswift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git", | ||
"state" : { | ||
"revision" : "32f641cf24fc7abc1c591a2025e9f2f572648b0f", | ||
"version" : "1.7.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "sourcekitten", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/jpsim/SourceKitten.git", | ||
"state" : { | ||
"revision" : "b6dc09ee51dfb0c66e042d2328c017483a1a5d56", | ||
"version" : "0.34.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser.git", | ||
"state" : { | ||
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", | ||
"version" : "1.2.3" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-syntax", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-syntax.git", | ||
"state" : { | ||
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b", | ||
"version" : "509.0.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swiftlint", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/realm/SwiftLint.git", | ||
"state" : { | ||
"revision" : "6d2e58271ebc14c37bf76d7c9f4082cc15bad718", | ||
"version" : "0.53.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swiftytexttable", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git", | ||
"state" : { | ||
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3", | ||
"version" : "0.9.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swxmlhash", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/drmohundro/SWXMLHash.git", | ||
"state" : { | ||
"revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f", | ||
"version" : "7.0.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "yams", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/jpsim/Yams.git", | ||
"state" : { | ||
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3", | ||
"version" : "5.0.6" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,11 @@ | |
import Foundation | ||
import Networking | ||
|
||
final class UploadService { | ||
private let uploadManager: UploadAPIManaging | ||
@NetworkingActor | ||
final class UploadService: Sendable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why also service needs to be sendable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The service will be removed in #59 |
||
static let shared = UploadService() | ||
|
||
init(uploadManager: UploadAPIManaging = UploadAPIManager()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we resign on injection approach here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The service will be removed in #59 |
||
self.uploadManager = uploadManager | ||
} | ||
|
||
deinit { | ||
uploadManager.invalidateSession(shouldFinishTasks: false) | ||
} | ||
johnkodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private let uploadManager = UploadAPIManager() | ||
} | ||
|
||
extension UploadService { | ||
|
@@ -60,7 +55,7 @@ extension UploadService { | |
} | ||
|
||
func uploadStateStream(for uploadTaskId: String) async -> UploadAPIManaging.StateStream { | ||
await uploadManager.stateStream(for: uploadTaskId) | ||
uploadManager.stateStream(for: uploadTaskId) | ||
} | ||
|
||
func pause(taskId: String) async { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ final class UploadsViewModel: ObservableObject { | |
|
||
private let uploadService: UploadService | ||
|
||
init(uploadService: UploadService = UploadService()) { | ||
init(uploadService: UploadService = .shared) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little bit confused. In FormUploadsViewModel we remove init with UploadService injection and we have just let variable with shared instance. I would prefer to have everywhere option to inject the service at least for the showcase, no matter we use just shared instance for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The service will be removed in #59 |
||
self.uploadService = uploadService | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ final class UsersViewModel: ObservableObject { | |
return decoder | ||
}() | ||
|
||
@NetworkingActor | ||
private lazy var apiManager: APIManager = { | ||
var responseProcessors: [ResponseProcessing] = [ | ||
LoggingInterceptor.shared, | ||
|
@@ -57,7 +58,13 @@ extension UsersViewModel { | |
} | ||
} | ||
|
||
return try await group.reduce(into: [User]()) { $0.append($1) } | ||
var results = [User]() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did we rewrite this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was getting the warning mentioned in this thread, however there is no response how to handle it, hence I rather decided to adjust the implementation 🤷♂️ |
||
|
||
for try await value in group { | ||
results.append(value) | ||
} | ||
|
||
return results | ||
} | ||
} else { | ||
// Fetch user add it to users array and wait for 0.5 seconds, before fetching the next one. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "collectionconcurrencykit", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git", | ||
"state" : { | ||
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95", | ||
"version" : "0.2.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "cryptoswift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git", | ||
"state" : { | ||
"revision" : "32f641cf24fc7abc1c591a2025e9f2f572648b0f", | ||
"version" : "1.7.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "sourcekitten", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/jpsim/SourceKitten.git", | ||
"state" : { | ||
"revision" : "b6dc09ee51dfb0c66e042d2328c017483a1a5d56", | ||
"version" : "0.34.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser.git", | ||
"state" : { | ||
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", | ||
"version" : "1.2.3" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-syntax", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-syntax.git", | ||
"state" : { | ||
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b", | ||
"version" : "509.0.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swiftlint", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/realm/SwiftLint.git", | ||
"state" : { | ||
"revision" : "6d2e58271ebc14c37bf76d7c9f4082cc15bad718", | ||
"version" : "0.53.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swiftytexttable", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git", | ||
"state" : { | ||
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3", | ||
"version" : "0.9.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swxmlhash", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/drmohundro/SWXMLHash.git", | ||
"state" : { | ||
"revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f", | ||
"version" : "7.0.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "yams", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/jpsim/Yams.git", | ||
"state" : { | ||
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3", | ||
"version" : "5.0.6" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ import Foundation | |
// MARK: - Defines API managing | ||
|
||
/// A definition of an API layer with methods for handling API requests. | ||
public protocol APIManaging { | ||
@NetworkingActor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we explain how does this work? When I define global actor for protocol, does it mean that all protocol methods by default run in this actor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a good explanation https://www.hackingwithswift.com/quick-start/concurrency/understanding-how-global-actor-inference-works |
||
public protocol APIManaging: Sendable { | ||
/// A default JSONDecoder used for all requests. | ||
var defaultDecoder: JSONDecoder { get } | ||
|
||
|
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.
why did we remove init method? I commented on UploadsViewModel the different approach we used
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.
The service will be removed in #59