Search code examples
node.jsnode.js-addon

Create a promise object with N-API native addons


I am looking for node.js native example code for creating a promise object from C (or C++) either by N-API (or node-addon-api) that can be used from node.js JavaScript layer. (More precisely the usage will be with async/await keyword). Any help on this highly appreciated. The following github repository was helpful, unfortunately I could not find an example for the one I am looking for.
https://github.com/nodejs/node-addon-examples
Thanks


Solution

  • Without knowing exactly what you're trying to accomplish (e.g., creating a promise that will be resolved in JavaScript or creating a promise that the C++ code will resolve) it's hard to answer specifically.

    But this doc probably has the information you need to make progress.

    https://github.com/nodejs/node-addon-api/blob/master/doc/promises.md