Question about your code
LawrenceHan opened this issue · 1 comments
LawrenceHan commented
Hi @ishkawa,
I've been reading your outstanding project, and I have 2 question about your code.
Could you please answer below questions if it's convenience.
In Session.swift Line:105, I've noticed you use a return
, I don't understand what's the purpose of that. Could you explain?
open func cancelRequests<Request: APIKit.Request>(with requestType: Request.Type, passingTest test: @escaping (Request) -> Bool = { _ in true }) {
adapter.getTasks { [weak self] tasks in
return tasks
.filter { task in
if let request = self?.requestForTask(task) as Request? {
return test(request)
} else {
return false
}
}
.forEach { $0.cancel() }
}
}
In URLSessionAdapter.swift Line:44, I've noticed you use a allTasks.map { $0 }
, is it necessary to map
it?
open func getTasks(with handler: @escaping ([SessionTask]) -> Void) {
urlSession.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in
let allTasks = dataTasks as [URLSessionTask]
+ uploadTasks as [URLSessionTask]
+ downloadTasks as [URLSessionTask]
handler(allTasks.map { $0 })
}
}
Thank you in advance.
ikesyo commented
Looks like both are unnecessary 🙃 Thank you for letting us know.