jperkin / node-rpio

Raspberry Pi GPIO library for node.js
858 stars 124 forks source link

rpio.poll(...) callback executed after polling stopped. #56

Closed newmanw closed 5 years ago

newmanw commented 6 years ago
function cb() {
  console.log('on poll');
}

rpio.poll(pin, cb);
...
rpio.poll(pin, null);
// The cb() function is often called after we deregister

Would it be possible to prevent callbacks on a pin from being sent if poll is deregistered?

ghost commented 6 years ago

Same problem here, got error: (node:10058) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 pin23 listeners added. Use emitter.setMaxListeners() to increase limit

ghost commented 6 years ago

Here is a little demonstration

var rpio = require('rpio')
rpio.init({ mapping: 'gpio' });

var pin = 23;

function foo () {
    console.log('foo');
}

rpio.open(pin, rpio.INPUT);
rpio.poll(pin, foo, rpio.POLL_HIGH);   
for (i = 0; i < 20; i++) {  
    rpio.poll(pin, null, rpio.POLL_HIGH);  
    rpio.poll(pin, foo, rpio.POLL_HIGH);     
}

rpio.open(pin, rpio.OUTPUT);
rpio.write(pin, rpio.LOW)

The script generates following output:

$ sudo node test.js (node:12646) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 pin23 listeners added. Use emitter.setMaxListeners() to increase limit foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo

I switched from 0.9.16 to 0.9.19, on 0.9.16 the problem was not present afaik.

Commit 0e5886ad71d4cc58b935d86eedf62c2e4325cb4e introduced this problem.

DaVarga commented 6 years ago

Still facing this problem. Any news about this?

Wouter0100 commented 5 years ago

@DaVarga could you test #77? It works on my end.

DaVarga commented 5 years ago

@Wouter0100 also works great for me. Thanks for this fix :+1:

Wouter0100 commented 5 years ago

Would be awesome. I tested your sample code, which worked. @DaVarga