On 12/3/13 6:56 AM, Sarav Sandhu wrote:
Hi Saul,
I couldn't understand why you have mentioned to call the idle callback
inside async callback. Why can't we just call the async callback and
consume the POSIX Message queue in it directly and do uv_write ?
Hi Sarav,
There are probably many ways to do things :-) The one I described has
worked for me very well. I use it from Python, so things are kind of
easier there :-)
The idea is:
1. From whatever thread, put your buffer into a thread safe queue
2. Call uv_async_send
3. In the async callback, start an idle handle, whose only duty is to
process the queue
4. When the idle handle callback is executed, it will process the queue
and stop
The reason why I use the idle handle is because the async handle can
coalesce the calls to send, so new items could be added to the queue
while I'm processing some of them. In my particular implementation, I
calculate the number of items in the queue when the idle callback is
called and only process those. If at the end of the callback the queue
contains more items, the handle is not stopped, they will be processed
in the next tick.
YMMV, of course.
--
Saúl Ibarra Corretgé
http://bettercallsaghul.com
--
You received this message because you are subscribed to the Google Groups
"libuv" 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].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/groups/opt_out.