(C++) Emitting events from another thread?

85 views
Skip to first unread message

Ingwie Phoenix

unread,
Jun 27, 2014, 12:25:09 PM6/27/14
to nod...@googlegroups.com
Hey hey! ^^

I am currently making concepts for a new module, that will embed PHP into nodejs so you can use it from a HTTP server, for instance. Thing is, I want to make it a non-blocking API. So I was thinking about returning an Event emitter with events for start, data, end and such. But is this even possible from another thread?

— Pseudo code.
var instance = new PHP({ini_setting: „value"});
instance.on(„data“, function(ch) { request.write(ch.toString(„utf-8")); });


This is supposed to be sort-of modeled after child_process.spawn. What posibilities do I have, to emit events across threads?

Kind regards, Ingwie.

mscdex

unread,
Jun 27, 2014, 4:45:28 PM6/27/14
to nod...@googlegroups.com, ingwi...@googlemail.com
On Friday, June 27, 2014 12:25:09 PM UTC-4, Ingwie Phoenix wrote:
This is supposed to be sort-of modeled after child_process.spawn. What posibilities do I have, to emit events across threads?


Have you already looked into `uv_async_send()` ? That would be for signalling the main thread (node) from your other thread (PHP). If you had a separate loop for PHP, you could use uv_async_send() to send in the other direction as well.

Ingwie Phoenix

unread,
Jun 28, 2014, 4:39:45 PM6/28/14
to Brian White, nod...@googlegroups.com

Am 28.06.2014 um 00:36 schrieb Brian White <msc...@mscdex.net>:

> On Fri, Jun 27, 2014 at 4:49 PM, Ingwie Phoenix
> <ingwi...@googlemail.com> wrote:
>> Do you happen to know the async type in uv? I am sure I have seen something
>> like uv_async_t…I just cant memorize it.
>
> It's documented in uv.h[1] and there is also a test[2] you can use as
> example usage.
>
> [1] https://github.com/joyent/libuv/blob/546fa7d508ba741c106d0161a31e9f8d257a5d56/include/uv.h#L1347-L1374
> [2] https://github.com/joyent/libuv/blob/master/test/test-async.c

Wow, thats a hardone. The test is not documented, so its hard to read/understand what it is doing, as it is using both - a thread and async object.
From the header, I only see that I have to asign a calback to an async object when initializing. So…I dont perfectly understand how this is supposed to work.

Do I need to make a thread first, then an async object, or how is this supposed to go?

Especially, how do I then send soemthing to the event loop?

Ingwie Phoenix

unread,
Jun 28, 2014, 4:39:45 PM6/28/14
to mscdex, nod...@googlegroups.com
Oi. Definitively going to check this out.

PHP is only a „one-shot“ thing. but if I ran it on the main thread, it’d be blocking. So it only runs thru, and once it emits „end“, its gone. o.o So, no two-way communication.
Thanks for pointing out the function!

Matthias Bleyl

unread,
Jun 30, 2014, 1:22:55 AM6/30/14
to nod...@googlegroups.com, ingwi...@googlemail.com
What about using a light-weight message bus, like http://www.zeromq.com/?
Does anybody has experiences with the combination of node.js and zeromq?

Alex Kocharin

unread,
Jul 2, 2014, 5:52:56 PM7/2/14
to nod...@googlegroups.com
 
I used zeromq with "zmq" package (wrote a client that connects to EMDR relay and reads data). Can't really say anything about it's performance, people seem to prefer axon for some reason.
 
 
30.06.2014, 10:20, "Matthias Bleyl" <matthia...@gmx.de>:
What about using a light-weight message bus, like http://www.zeromq.com/?
Does anybody has experiences with the combination of node.js and zeromq?

 

--
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 nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/63930f30-4f7e-451c-81b0-c95832d9271d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sam Roberts

unread,
Jul 2, 2014, 5:52:56 PM7/2/14
to nod...@googlegroups.com
On Fri, Jun 27, 2014 at 8:16 AM, Ingwie Phoenix
<ingwi...@googlemail.com> wrote:
> Hey hey! ^^
>
> I am currently making concepts for a new module, that will embed PHP into nodejs so you can use it from a HTTP server, for instance. Thing is, I want to make it a non-blocking API. So I was thinking about returning an Event emitter with events for start, data, end and such. But is this even possible from another thread?

Not sure why you are contemplating this, but if you want a hybrid
language app, check out mongrel2:

http://mongrel2.org/features/languages.html

It supports php and node.

Sam

Ingwie Phoenix

unread,
Jul 2, 2014, 7:59:06 PM7/2/14
to nod...@googlegroups.com
The reason is simply to reduce the worktime in one language. My plan is to just send a message thru REDIS to nodejs and let it do stuff. But since technically no webservers support WebSockets, I need to also make my webserver in nodejs.

That is, if Mongrel2 wont do it either. It looks extremely interesting and I will see what I can make out of it! Thanks for sharing that.
Reply all
Reply to author
Forward
0 new messages