aantron / promise

Light and type-safe binding to JS promises
MIT License
340 stars 24 forks source link

Provide way to use tuples instead of list for "all" #36

Closed kgoggin closed 5 years ago

kgoggin commented 5 years ago

Hey there! Thanks so much for this library - I'm really enjoying using it in my project over the standard Js.Promise.t!

One API that Js.Promise provides that I do miss, however, is the ability to resolve a set of promises in parallel that don't all have the same type via a tuple.

From the JS side, I think the implementation would be pretty easy:

let all2 = (p1, p2) =>
    [|p1, p2|]
    |> jsAll
    |> map (results => {
      let mappedResults = results |> Array.map(unwrap);
      (mappedResults[0], mappedResults[1])
    });

But, I'm not as familiar with writing native Reason code, so I've got no idea if it'd be that straightforward there... and if it isn't, I presume the idea would be to keep the API the same for native and JS, right?

aantron commented 5 years ago

Thanks for the suggestion :)

This should be easy to implement on native as well. I can do it later today/tomorrow :) I'd probably create all2-all6, relying on the precedent that Js.Promise goes up to all6.

kgoggin commented 5 years ago

Awesome! Yeah, I think replicating the Js.Promise makes great sense. Can't wait to try it out!

aantron commented 5 years ago

Okay, all2-all6 are merged in, for both JS and native:

https://github.com/aantron/repromise/blob/a166c2bc37a04fdc1a142786d8e6a580e5203608/src/js/repromise.rei#L21-L40

Sorry about the delay, I needed to take a break from public work for a while :/

kgoggin commented 5 years ago

@aantron that's awesome, thanks so much! And no worries about the delay - hope all is well. Thanks again for this great lib!

aantron commented 5 years ago

Great :)

Are you depending on Repromise from GitHub? Would you prefer a speedy release of these functions to NPM?

kgoggin commented 5 years ago

Yeah, I'm using the npm package, not GH, but I'm also not stuck waiting on this. So, no rush to ship a new release if you want to wait a bit.

aantron commented 5 years ago

Ok, thanks. I'll see if I get around to doing anything else soon-ish, then do a release.

kgoggin commented 5 years ago

Hi! I just bumped up another use for this - would you mind cutting a release with this code when you have a chance?

aantron commented 5 years ago

This is now out as 0.6.1. The changelog is here. Sorry for the delay, I was on hiatus.