有什么方法可以解析下面的代码,并将其值作为数组Future <[Object],Error>返回。我正在使用BrightFutures未来的实现方式
return apiService.getArrayObject()
.flatMap(NetworkQueue.context) { (arrayObjects: [ArrayObject]) -> Future<[Object], Error> in
let objects = arrayObjects.map {
apiService.getObject(of: $0.objectId)
}
return objects // ERROR since objects is [Future<Object,Error>] rather than needed output
}
答案 0 :(得分:0)
使用顺序
return apiService.getArrayObject()
.flatMap(NetworkQueue.context) { (arrayObjects: [ArrayObject]) -> Future<[Object], Error> in
let objects: [Future<Object, Error>] = arrayObjects.map {
apiService.getObject(of: $0.objectId)
}
let sequenceFuture: Future<[Object], NoError> = objects
.sequence()
return sequenceFuture
}