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

Expose EventEmitter methods on gpio.promise #103

Merged
merged 2 commits into from
May 25, 2020
Merged

Expose EventEmitter methods on gpio.promise #103

merged 2 commits into from
May 25, 2020

Conversation

pimterry
Copy link
Contributor

The docs say:

This API exposes a Promises interface to the module. All of the same functions are available, but do not take callbacks and instead return a Promise.

That's not quite true, because this doesn't work:

const gpio = require('rpi-gpio').promise;
gpio.on('change', console.log); // TypeError: gpio.on is not a function

This PR fixes that in the simplest way, by just exposing all the interesting event emitter methods from GPIO on the promise object, bound back to GPIO.

These methods don't actually use promises of course, but being able to use .promise as a drop-in replacement is super useful imo, and from the docs above it seems like that's what you're aiming for.

@JamesBarwell
Copy link
Owner

Good spot, thanks for the PR. It looks like we can't proxy off because that didn't exist until node v10, which is why the tests are failing. Could you update the PR to remove that one? Happy to get this merged when it's passing.

I think it's correct that the event bindings are not promised based. I think callbacks are always the appropriate interface for these.

@JamesBarwell JamesBarwell merged commit 8801088 into JamesBarwell:master May 25, 2020
@JamesBarwell
Copy link
Owner

Thanks! Published as 2.1.7.

@pimterry
Copy link
Contributor Author

Great stuff, thanks!

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

Successfully merging this pull request may close these issues.

2 participants