O'Reilly logo

Mastering Node.js - Second Edition by Kevin Faaborg, Sandro Pasquali

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Asynchronous add-ons

In keeping with the typical pattern of a Node program, add-ons also implement the notion of asynchronous callbacks. As one might expect in a Node program, a C++ add-on performing an expensive and time-consuming operation should comprehend the notion of asynchronously executing functions.

Let's create a module that exposes two methods that ultimately call the same function, yet one method does it synchronously and the other asynchronously. This will allow us to demonstrate how to create native modules with callbacks.

We're going to break our module up into 4 files, separating functionality. Create a new directory and copy the package.json file from the previous example (changing name to something else), and add the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required