Is there any reason why the promise below is only firing once?
console.log('start')
var Promise = require('bluebird')
var onoff = require('onoff')
var Gpio = onoff.Gpio
var button = new Gpio(4, 'in', 'both')
var buttonWatchAsync = function (button, desiredValue) {
return new Promise (function (resolve, reject) {
return button.watch(function(err, value) {
if (err) return reject(err)
if (typeof desiredValue === 'undefined') return resolve(value)
if (desiredValue === value) return resolve()
})
})
}
buttonWatchAsync(button)
.then(function (value) {
console.log('fired promise')
console.log(value)
})
.catch(function (err) {
throw err
})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…