node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

Need an example of using napi_create_async_work()

Open gabrielschulhof opened this issue 8 years ago • 8 comments

https://github.com/nodejs/node/issues/13512 seems to indicate that we should have such an example.

gabrielschulhof avatar Nov 02 '17 18:11 gabrielschulhof

There it is on nodejs repo test napi. But bug or not a bug. Process crashes when invoking the same async function twice and more times. Did you tried their sample on your comp?

Globik avatar Jan 05 '18 18:01 Globik

By the way here is a simplified example of napi create async work: https://github.com/Globik/libqrencode-js/blob/master/simple_test/test_async.c In pure C.

Globik avatar Jan 05 '18 18:01 Globik

Emit event from cpp is good, but how to the same with a pure c's node_api.h?

Globik avatar May 19 '18 18:05 Globik

If you are wandering about how to emit an event from plain C to node.js: https://github.com/Globik/kore-mediasoup/tree/master/addon/emitter

Globik avatar May 20 '18 18:05 Globik

@Globik it would be great if you could create examples that could be added to: https://github.com/nodejs/abi-stable-node-addon-examples

mhdawson avatar May 25 '18 20:05 mhdawson

@mhdawson how to do it? Do I need a pull request with examples?

Globik avatar Jun 15 '18 07:06 Globik

@Globik you can create PR that adds the example to that repository.

mhdawson avatar Jun 18 '18 18:06 mhdawson

@mhdawson and the sample like this will do? Glib loop in a dedicated thread within nodejs addon N-API: https://github.com/Globik/kore-mediasoup/blob/master/addon/emitter5/uv_glib.c

Globik avatar Jun 18 '18 19:06 Globik