Syntax error when attempting to do work in .then{} prior to executing next Promise function
- Dominant language
- Objective-C
- Stars
- 3.8k
- Forks
- 316
- PR merge metrics
- No merged PRs in 30d
Description
```swift
getEventsFromDatabase(for: today)
.then { data in
// Diff
self.getEventsFromNetwork(for: today, event: data)
}
.then { data in
self.progress.progress = 0.5
self.parsePDF(data)
}
.then { data in
self.progress.progress = 0.5
self.updateViewData(for: self.todayEvents, data: data)
}
```
The above code works as advertised in the documentation.
```swift
getEventsFromDatabase(for: today)
.then { data in
self.progress.progress = 0.2 // Diff
self.getEventsFromNetwork(for: today, event: data)
}
.then { data in
self.progress.progress = 0.5
self.parsePDF(data)
}
.then { data in
self.progress.progress = 0.5
self.updateViewData(for: self.todayEvents, data: data)
}
```
In the first closure I add a block of code to update the UIProgressView.
Syntax error: Missing return in a closure expected to return 'Promise'
A look at the individual function differences:
### 1
```swift
private func getEventsFromDatabase(for date: Date) -> Promise<[NonCodableEvent]> {
return Promise {
return try DatabaseController.getEventsForDate(date: date, container: self.persistentContainer)
}
}
```
### 2
```swift
private func getEventsFromNetwork(for date: Date, event: [NonCodableEvent]) -> Promise {
if(event.count > 0) {
return Promise(on: .global()) { () -> [NonCodableEvent] in
return event
}
}
return Promise(on: .global()) { () -> Any in
let (data, response, error) = ServiceLayer().request(route: NavyRoute(squadron: Squadron.ht8, date: date))
if let error = error {
throw error
}
//TODO: Handle response code issues
return data
}
}
```
In '1', I'm returning a "generic" promise on the .main thread.
In '2', I'm returning a Promise explicitly run on the .global thread.
Trying to wrap my head around why this might be causing issues, or if there's something else I'm missing.
Contributor guide
Assessment
This issue has not been assessed yet.