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

Coerce to JS.Promise #25

Closed
lpil opened this issue Jul 22, 2018 · 4 comments
Closed

Coerce to JS.Promise #25

lpil opened this issue Jul 22, 2018 · 4 comments

Comments

@lpil
Copy link

lpil commented Jul 22, 2018

There are various Bucklescript libraries today that take Js.Promises are arguments (i.e. bs-express). It would be great to use Repromise with these libraries!

Would it be possible to have a coerce function that converts a Repromise promise to a Js.Promise?

Thanks,
Louis

@aantron
Copy link
Owner

aantron commented Jul 22, 2018

Agreed. I'll have to think about how to package these, because they need to go in the .rei file, but the .rei file is shared between JS and native, and Js.Promise doesn't exist on native. Might have to split the .rei files, so each implementation gets its own. I guess it won't be a big deal in terms of them going out of sync, because we still subject both JS and native Repromise to the same tests.

In the meantime, here is how these can be defined:

external fromJSPromise:
  Js.Promise.t('a) => Repromise.Rejectable.t('a, Js.Promise.error) =
  "%identity";

external toJSPromise:
  Repromise.Rejectable.t('a, _) => Js.Promise.t('a) = "%identity";

@aantron
Copy link
Owner

aantron commented Jul 23, 2018

Ok, I added the functions to master, as Repromise.Rejectable.fromJsPromise and Repromise.Rejectable.toJsPromise.

The commit also includes tests and docs.

Thanks for prompting this :)

@lpil
Copy link
Author

lpil commented Jul 23, 2018

Thank you!

@aantron
Copy link
Owner

aantron commented Jul 27, 2018

This is now in NPM in @aantron/repromise 0.6.0. Thanks again for prompting it :)

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

No branches or pull requests

2 participants