Skip to content

Commit 244be64

Browse files
async
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
1 parent 119b145 commit 244be64

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Sources/NextcloudKit/NextcloudKit+Dashboard.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ public extension NextcloudKit {
4242
options.queue.async { request(dashboardRequest) }
4343
}
4444

45+
func getDashboardWidgetAsync(account: String,
46+
options: NKRequestOptions = NKRequestOptions(),
47+
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in }) async -> (account: String,
48+
dashboardWidgets: [NCCDashboardWidget]?,
49+
responseData: AFDataResponse<Data>?,
50+
request: DataRequest?,
51+
task: URLSessionTask?,
52+
error: NKError) {
53+
await withCheckedContinuation { continuation in
54+
var capturedRequest: DataRequest?
55+
var capturedTask: URLSessionTask?
56+
57+
getDashboardWidget(account: account, options: options, request: { req in
58+
capturedRequest = req
59+
}, taskHandler: { task in
60+
capturedTask = task
61+
taskHandler(task) // lo inoltriamo comunque al chiamante
62+
}, completion: { account, widgets, response, error in
63+
continuation.resume(returning: (account, widgets, response, capturedRequest, capturedTask, error))
64+
})
65+
}
66+
}
67+
4568
func getDashboardWidgetsApplication(_ items: String,
4669
account: String,
4770
options: NKRequestOptions = NKRequestOptions(),
@@ -77,6 +100,30 @@ public extension NextcloudKit {
77100
}
78101
options.queue.async { request(dashboardRequest) }
79102
}
103+
104+
func getDashboardWidgetsApplicationAsync(_ items: String,
105+
account: String,
106+
options: NKRequestOptions = NKRequestOptions(),
107+
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in }) async -> (account: String,
108+
dashboardApplications: [NCCDashboardApplication]?,
109+
responseData: AFDataResponse<Data>?,
110+
request: DataRequest?,
111+
task: URLSessionTask?,
112+
error: NKError) {
113+
await withCheckedContinuation { continuation in
114+
var capturedRequest: DataRequest?
115+
var capturedTask: URLSessionTask?
116+
117+
getDashboardWidgetsApplication(items, account: account, options: options, request: { req in
118+
capturedRequest = req
119+
}, taskHandler: { task in
120+
capturedTask = task
121+
taskHandler(task) // propaghiamo al chiamante
122+
}, completion: { account, apps, response, error in
123+
continuation.resume(returning: (account, apps, response, capturedRequest, capturedTask, error ))
124+
})
125+
}
126+
}
80127
}
81128

82129
public class NCCDashboardApplication: NSObject {

0 commit comments

Comments
 (0)