【问题标题】:Callback of libraries are blocking in Node库的回调在 Node 中被阻塞
【发布时间】:2017-07-05 13:25:40
【问题描述】:

我尝试使用这两个库来检测 NFC 标签 (https://github.com/mitchellparsons/rc522-rfid-promise) 并控制 Raspberry Pi 上的 MPD 服务器 (https://github.com/andrewrk/mpd.js)。我在 Raspbian Jessie (2017-01-11) 上使用 Node v6.9.5。

执行以下代码时,仅执行 MPD 侦听器。是不是我做错了什么或者误解了 Nodejs 的概念?

var mpd = require('mpd')
var rc522 = require("rc522-rfid-promise")

var client = mpd.connect({
  port: 6600,
  host: 'localhost',
})

rc522.startListening()
  .then(function(rfidTag){
    console.log('Got RFID tag')
})

client.on('ready', function() {
  console.log("MPD ready")
})

谢谢!

【问题讨论】:

    标签: javascript node.js raspberry-pi mpd


    【解决方案1】:

    尝试监听错误事件:

    client.on('error', function (err) {
      console.log('Error:', err)
    });
    

    【讨论】:

    猜你喜欢
    • 2018-05-23
    • 2013-11-16
    • 2014-11-18
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    相关资源
    最近更新 更多