Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zip with promises array #2

Closed
fmo91 opened this issue Feb 7, 2017 · 7 comments
Closed

Zip with promises array #2

fmo91 opened this issue Feb 7, 2017 · 7 comments
Assignees

Comments

@fmo91
Copy link

fmo91 commented Feb 7, 2017

Hey, great library! I have been looking for something like this for a while.

I'd like to suggest that zip should receive an array of promises (if all of them shares the same return type) and a return a promise that combines all the inputs. It could also receive a reduce function as argument. What do you think?

I mean something like this:

var promises = [Promise<User>]()

// Some code here. 

Promise.zip(promises)
      .then { (users: [User]) in 

      }

Thanks!

@malcommac malcommac self-assigned this Feb 8, 2017
@malcommac
Copy link
Owner

Hi @fmo91 , thank you :)
I'm sorry but I think I don't really understand the request; sure I could introduce a zip operator with an array as input but why input array are promises? How you will combine them? Am I missing something? Can you provide to me an example of the usage.

@fallback
Copy link

fallback commented Feb 8, 2017

I think, @fmo91 intends to describe the situation when, for example, you're going to load.. say, admin users with one promise, then managers with another promise. Type of result for both is Promise. And then, when all these promises are fulfilled, he want to get an array of User entities.
From my personal side, I see no big reasons for this scenario, however, I might be useful for @fmo91 .

@fmo91
Copy link
Author

fmo91 commented Feb 8, 2017

Sorry for the late response. Yes, that's exactly what I'm describing. I have to upload images in base64 to the backend. I'm currently using RxSwift, so each upload returns an Observable, and then I use .zip to merge all these Observable and wait them to complete.
I believe a zip function that accepts an array of Promises in your case would be great. Or is there another way to do the same?

@malcommac
Copy link
Owner

You can create your promises and use all to execute all of them and wait for results.
However if one promise fails the entire chain also fail; is this the behaviour you need?

@malcommac
Copy link
Owner

Ping :)

@fmo91
Copy link
Author

fmo91 commented Feb 15, 2017

Yes, that's exactly what I was looking for. Thank you!

@malcommac
Copy link
Owner

U're welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants