async
async copied to clipboard
add and that takes one and two future
This PR is to add the "and" syntactic sugar to the future structure.
Motivations:
Often times when working with vapor we have to get futures from multiple places such as body content, and database connections. Joining these together to work with them in Map chaining is nice syntactic sugar.
Limitations:
It seems that tuples can be destructured into arguments according to the compiler, the systactic sugar is nice, but not as nice as I would like.
Acctual
var futureT = Future(t)
var futureS = Future(s)
futureT.and(futureS).map(to: V.self) { tAndS in
return ///
}
Desired
var futureT = Future(t)
var futureS = Future(s)
futureT.and(futureS).map(to: V.self) { t, s in
return ///
}
Future Thoughts:
It would be nice if generics could handle Type lists, however, I think this beyond the scope of what swift 4 can do at the moment as such making a generic that can handle variadic arguments is beyond the scope of this work. I could definitely be wrong and there could be a way to hand N amount of futures in which case, lets do it.
If this is not accepted here please add to the new https://github.com/vapor-community/async-extensions repo :D
okie
Just an FYI, you can do
return map(to: V.self, futureT, futureS) { t, s in
return ///
}
@0xTim Yes, there is that option available, but you can't add it onto a future chain, which is where .and will come in.