Hi everyone,

*TL;DR*: We created a *pull request 
<https://github.com/nodejs/node/pull/19005>* to allow an easier and more 
flexible development experience when embedding Node.js into C++ 
applications by giving more control to the application developer while 
staying backwards compatible with the existing interface (node::Start(argc, 
argv), etc.). We would love to hear your *feedback*.


Motivation 

As a C++ application developer, it can sometimes be hard to find maintained 
libraries with appropriate licenses. Furthermore, it can be relatively 
difficult to integrate C++ libraries into projects. In order to unlock the 
full potential of the NPM package ecosystem for C++ applications, we 
embedded Node.js as a shared library. We wanted to build a Qt based C++ 
application using NPM packages for data retrieval. However, we ran into 
various difficulties during the development process, such as:

   - sparse documentation
   - low controlability 
      - event loop blocks calling thread, once Node.js is started
      - parameters (e.g. for Start(argc, argv)) are difficult to construct
   
Thus, we tried to improve the usability of Node.js as a shared library.


Flexible event loop 

We wanted to give the user full control over the behavior of the Node.js 
event loop. Although the initial implementation allowed the user to start 
the event loop with just one call, we missed the possibility to also stop 
and resume the loop at will. Therefore, we introduced two different ways 
for the user to interact with the event processing in Node.js: The user 
might just (1) let Node.js take care of the event loop. This interaction is 
very close to the initial behavior, since the node::RunEventLoop(callback) 
blocks the calling thread until all events are processed. However, the user 
gains the possibility to react to changes by providing a callback, which is 
executed once per loop tick. The other way of controlling the event loop is 
by (2) executing single event loop ticks. By calling node::ProcessEvents(), 
Node.js processes events once and returns to the caller.




*Be sure to check out our pull request on Github 
<https://github.com/nodejs/node/pull/19005>, including code examples.*What 
are your thoughts? Would you use such an interface? Is there something you 
would like us to change?

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/8078a960-3d54-44b3-8007-4bdef82111aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to