title: Callback function in Node.js addon
body: <p>I am wrapping a CAN Bus manager API in a node.js extension.
  Everything works well, this would be the final result:</p>
  
  <pre><code>// list interfaces
  var interfaces = addon.listDevices();
  console.log(interfaces);
  
  // Allocating a new port
  var port = new addon.CANPort();
  port.setCallback(function(msg) {
      // I would like to receive all CAN datagrams
      console.log(msg);
  });
  
  // Connect to the 1st port
  port.connect(0);
  // Send a datagram
  port.sendStruct(127508, 6, Array(0, 70, 5, 50, 0, 131, 114, 0));
  </code></pre>
  
  <p>Every function is OK but the setCallback function. Actually, I don't know what to do.
  I have a c++ callback of this this type :</p>
  
  <pre><code>void CANPort::SetReceiveCallback(functionCallback func);
  </code></pre>
  
  <p>which will call the function when it receives a new datagram.</p>
  
  <p>I found in <a href="http://nikhilm.github.io/uvbook/threads.html" rel="nofollow">http://nikhilm.github.io/uvbook/threads.html</a> some help, but I can't find the right way to do the same as the last example. I know I should use uv, but I don't know how...</p>
  
  <p>Moreover, I'm using the v0.11.14-pre of Node.js, so a lot of documentation is out of date...</p>
  
  <p>Thanks,
  Nicolas.</p>