-
-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
NAPI_STATUS_THROWS(napi_create_threadsafe_function( | ||
env, | ||
callback, | ||
0, | ||
async_resource_name, | ||
0, | ||
3, | ||
100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to set something for queue size. If we set to 0 it means we get an unlimited queue and this will crash.
0, | ||
3, | ||
100, | ||
1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I changed this from 3 to 1, since we haven't actually started the threads yet, so can't assume there are three threads running.
dcn_context_t* dcn_context = (dcn_context_t*)arg; | ||
dc_context_t* dc_context = dcn_context->dc_context; | ||
|
||
napi_acquire_threadsafe_function(dcn_context->napi_event_handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will bump internal thread count.
dc_perform_imap_jobs(dc_context); | ||
dc_perform_imap_fetch(dc_context); | ||
dc_perform_imap_idle(dc_context); | ||
} | ||
|
||
napi_release_threadsafe_function(dcn_context->napi_event_handler, napi_tsfn_release); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will reduce thread count.
dc_perform_smtp_jobs(dc_context); | ||
dc_perform_smtp_idle(dc_context); | ||
} | ||
|
||
napi_release_threadsafe_function(dcn_context->napi_event_handler, napi_tsfn_release); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto for this function.
@@ -266,6 +297,7 @@ NAPI_METHOD(dcn_context_new) { | |||
dcn_context->napi_event_handler = NULL; | |||
dcn_context->imap_thread = 0; | |||
dcn_context->smtp_thread = 0; | |||
dcn_context->loop_thread = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this should be 0, since we don't have any threads running atm. It doesn't really matter though.
dcn_context->dc_context); | ||
uv_thread_create(&dcn_context->smtp_thread, smtp_thread_func, | ||
dcn_context->dc_context); | ||
dcn_context->loop_thread = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we set it to 1.
We can probably tweak this more later, but at least we can now stop gracefully, which is needed in order to implement tests properly. |
Also see nodejs/help#1387 and nodejs/node@45816c5 for reference |
Also see comments in code below.
Output:
Note that the last output is written to stdout after we are back on the js side.