fully working control example with interrupts

master
David Kebler 2017-02-02 01:41:42 -08:00
parent 4485f981a5
commit efd1834d14
1 changed files with 10 additions and 2 deletions

View File

@ -27,7 +27,10 @@ class Interrupt extends EventEmitter {
this.dbt = opts.debounce ? opts.debounce : 200 this.dbt = opts.debounce ? opts.debounce : 200
this.poller = new Epoll( this.poller = new Epoll(
debounce((err, fd, events) => { debounce((err, fd, events) => {
if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) } if (err) { this.emit('error', err) } else {
// this.clear().then(this.emit('fired', this.hook))
this.emit('fired', this.hook)
}
}, this.dbt, true) // true = leading }, this.dbt, true) // true = leading
) )
} }
@ -36,6 +39,7 @@ class Interrupt extends EventEmitter {
process.on('SIGINT', () => { process.on('SIGINT', () => {
this.exit().then((resp) => console.log("\n", resp)) // unexport on cntrl-c this.exit().then((resp) => console.log("\n", resp)) // unexport on cntrl-c
.catch(err => console.log("error:", err))
}) })
return _.pSeries([ return _.pSeries([
@ -81,7 +85,11 @@ class Interrupt extends EventEmitter {
} }
start() { start() {
this.clear().then(() => this.poller.add(this.valuefd, Epoll.EPOLLPRI)); this.clear().then(() => this.poller.add(this.valuefd, Epoll.EPOLLPRI | Epoll.EPOLLONESHOT));
}
reset() {
this.clear().then(() => this.poller.modify(this.valuefd, Epoll.EPOLLPRI | Epoll.EPOLLONESHOT));
} }
stop() { stop() {