resync icon indicating copy to clipboard operation
resync copied to clipboard

Promise converter

Open Koleok opened this issue 6 years ago • 2 comments

First of all 👏 👏 on this lib, i have held off on using reason at work for almost a year due to there not being some kind of reasonable monad-y solution to async like fluture which i use in my js daily. resync is exactly what i hoped someone would publish eventually.

On that note, since there are, and always will be, lots of third party libs that return promises, it'd be nice to have something like encaseP to wrap these functions with and not worry about promises from that point on (you already have from_js which is much like encaseN).

I understand this may be a larger ask than it would in js, if you'd rather offload it than i'd be glad to take a crack at it, I also just wonder if there is any consensus among other resync users that this util should even exist.

Koleok avatar Apr 05 '18 16:04 Koleok

Hi. Thanks for the feedback, it's much appreciated ;)

I don't think that adding promise support should be too much of a problem. But I didn't start adding it because I didn't have a need for it. Many JS libraries support both callbacks and promises - and so far, the only library I'm integrating to is the mongo driver.

One difference to bear in mind that this library is simply a wrapper around functions that take a callback as an argument, where the promise is basically a state machine - a promise is either pending or settled.

Anyway. I will not have the time to look at it for the next month, I'm too busy with other things, but if you want to give it a shot, I'll happily look at pull-requests.

Btw. if you have better naming suggestions, I'm open to suggestions. I never liked the name from_js but I couldn't think of anything better. encase sounds a bit better.

stroiman avatar Apr 08 '18 10:04 stroiman

@stroiman I am going to fiddle around today with doing something like promise-to-callback probably just a binding wrapper and then try to re-implement if it works.

Koleok avatar Apr 13 '18 15:04 Koleok