Code Monkey home page Code Monkey logo

addon-event-emitter's Introduction

Event Emitter on Node.js Native Addons using N-API

How to create and use Event Emitter on Node.js Native Addons

Node.js includes an event system which is an implementation of the Observer pattern that is the most common used event pattern in Node.js application and for good reasons: it's incredibly simple and useful.

Anyone who has used Node.js should be familiar with events. This module has the responsability to facilitate the communication between objects of your application.

Much of the Node.js core API modules are built aroud an idiomatic asynchronous event-driven architecture in which certains kinds of objects (called emitter) periodically emit named events that cause Function objects ("listeners") to be called.

Sometimes you need to promote loose coupling system by ensuring that instead of components (modules) referring to each other explicitly, their interaction is handled through an exchange of message using the events. This can help to decouple the systems and improve the module reusability.

Here you can find a collection of examples where I used or implemented event emitter interface in a Node.js Native AddOns.

In each example directory, run:

$ npm install
$ node-gyp rebuild
$ node index.js or npm start

Examples

Node.js C / C ++ Addons

N-API

Node Addon API

Header-only C++ wrapper classes for the ABI-stable Node.js API

Web resources

Nicola Del Gobbo

https://github.com/NickNaso/

https://www.npmjs.com/~nicknaso

https://twitter.com/NickNaso

Acknowledgements

Thank you to all people that encourage me every day.

License

Licensed under Apache license V2

addon-event-emitter's People

Contributors

nicknaso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

addon-event-emitter's Issues

n-api emit from a thread

Hello!

How are you?

Do you know how emitting works if I try to use this from a running thread?

Can it be global?

Is it really useful? I think it is like phocus or magic, not very useful.
I mean every emmiter instance should be as a global variable, not in a function scope like you did.
Can it be globalish like this:
Napi::Function emit = nullptr; ?
It looks like no:
Napi::Function emit = info[0].AsNapi::Function();
This emit should be global cuz from any part of code could be emit an event. Alas. Not in this case. As I understand info also can't be globalish. It is very pitty!
Just a phocus. You really emit an event from within node.js, not from cpp!!!
but should to do a real event from any part of cpp code workflow to node.js
Just like as if promises doing that.

And else one moment. I really don't undestand for what all developers using those f*** c++ wrapper when napi addons purposes to support pure C language?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.