You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All uv_run calls for the event loop of nodeJS from either idle handles of Julia event loop or scheduled tasks (e.g. by @async) raises RangeError: Maximum call stack size exceeded.
For example,
using NodeCall
import NodeCall: UvRunMode, UV_RUN_NOWAIT
functionsometask()
node"setTimeout(() => console.log('Done'), 2000)"
loop =node_uvloop()
@asynclet ret =1while ret !=0sleep(0.5) # or `yeild()` to make the task not blocking
ret =@ccall:libjlnode.uv_run(loop::Ptr{Cvoid}, UV_RUN_NOWAIT::UvRunMode)::Cintendendend
p =sometask()
wait(p)
throws
undefined:0
RangeError: Maximum call stack size exceeded
Thrown at:
Activity
[-]Promises[/-][+]Async call to livnode.uv_run[/+][-]Async call to livnode.uv_run[/-][+]Async call to libnode.uv_run[/+][-]Async call to libnode.uv_run[/-][+]Async call to node api[/+]sunoru commentedon Jul 20, 2021
Actually, any async functions that invoke any node-API would throw this. It is because the API must be used in the main thread.
Even showing js values in REPL will throw this error:
sunoru commentedon Aug 7, 2021
Try using N-API's async APIs.sunoru commentedon Aug 10, 2021
https://nodejs.org/docs/latest-v14.x/api/n-api.html#n_api_asynchronous_thread_safe_function_calls
We probably have to invoke by
napi_threadsafe_function.Maybe it's not worth supporting
@async, since we can always use@node_asyncto let NodeJS control the event loop.Perhaps a function can be provided to wrap a
Taskwith an async context?I'm still not sure how the other
napi_functions should be used in an async environment.Will test later.sunoru commentedon Aug 11, 2021
Instead of wrapping
Tasks, we can directly modifynapi_callto invokenapi_create_threadsafe_functionifcurrent_task() != global_task().See thethreadingbranch and https://github.com/sunoru/jlnode/tree/threading