Reputation: 2102
I'm a bit confuse about the difference between Promises.zip
and Promises.all
in this Promise Library
Which one should I use if I want to execute 2 task in parallel and then use both their result for another task?
Upvotes: 0
Views: 306
Reputation: 6018
If you look at implementation of Promises.all
and Promises.zip
you see, that .all
can work with Promise
s with same type:
public static func all<T>(_ promises: [Promise<T>]) -> Promise<[T]>
But .zip
can work with different types:
public static func zip<T, U>(_ first: Promise<T>, _ second: Promise<U>) -> Promise<(T, U)>
This is basic difference between these two.
P.S. Also, if you try to search in github by zip
keyword, you can find this issue, that helps you to understand the situation. So, always search first ;)
Upvotes: 2