Skip to content

Commit b9ebf1f

Browse files
committed
fix: dispatching call to current thread
1 parent 9c04aff commit b9ebf1f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/host/cpp/ThreadsafeFunction.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,12 @@ napi_status ThreadSafeFunction::call(
139139
log_debug("Error: No CallInvoker available for ThreadSafeFunction");
140140
return napi_generic_failure;
141141
}
142-
// Hop to JS thread; we drain one item per hop to keep latency predictable
143-
// and avoid long monopolization of the JS queue.
144-
invoker->invokeAsync([self = shared_from_this()] { self->processQueue(); });
142+
// Invoke from the current thread. Libraries like NativeScript can wrap a
143+
// JS function in an Objective-C block to be dispatched onto another thread
144+
// (e.g. the main thread, with the intention of accessing the UI), and so we
145+
// should run the JS function on the same thread the Objective-C block was
146+
// dispatched to.
147+
invoker->invokeSync([self = shared_from_this()] { self->processQueue(); });
145148
return napi_ok;
146149
}
147150

0 commit comments

Comments
 (0)