File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ NodeIntegration::NodeIntegration()
1919 embed_closed_ (false ) {
2020}
2121
22+ constexpr uint64_t EVENT_BATCH_TIMEOUT_MS = 8 ;
23+ constexpr int EVENT_BATCH_SIZE = 64 ;
24+
2225NodeIntegration::~NodeIntegration () {
2326 // Quit the embed thread.
2427 embed_closed_ = true ;
@@ -76,6 +79,17 @@ void NodeIntegration::ReleaseHandleRef() {
7679void NodeIntegration::WakeupMainThread () {
7780 PostTask ([this ] {
7881 this ->UvRunOnce ();
82+ // ^ This also updates the uv_now() timestamp.
83+ uint64_t start_time_ms = uv_now (uv_loop_);
84+
85+ int loop_count = EVENT_BATCH_SIZE;
86+ uint64_t elapsed_ms = 0 ;
87+ while (loop_count != 0 && (elapsed_ms < EVENT_BATCH_TIMEOUT_MS)) {
88+ loop_count--;
89+ this ->UvRunOnce ();
90+ elapsed_ms = uv_now (uv_loop_) - start_time_ms;
91+ }
92+
7993 // Tell the worker thread to continue polling.
8094 uv_sem_post (&this ->embed_sem_ );
8195 });
You can’t perform that action at this time.
0 commit comments