Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 91384bf

Browse filesBrowse files
Gabriel Schulhoftargos
authored andcommitted
n-api: add API for asynchronous functions
Bundle a `uv_async_t`, a `uv_idle_t`, a `uv_mutex_t`, a `uv_cond_t`, and a `v8::Persistent<v8::Function>` to make it possible to call into JS from another thread. The API accepts a void data pointer and a callback which will be invoked on the loop thread and which will receive the `napi_value` representing the JavaScript function to call so as to perform the call into JS. The callback is run inside a `node::CallbackScope`. A `std::queue<void*>` is used to store calls from the secondary threads, and an idle loop is started by the `uv_async_t` callback on the loop thread to drain the queue, calling into JS with each item. Items can be added to the queue blockingly or non-blockingly. The thread-safe function can be referenced or unreferenced, with the same semantics as libuv handles. Re: nodejs/help#1035 Re: #20964 Fixes: #13512 PR-URL: #17887 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 0d98fe6 commit 91384bf
Copy full SHA for 91384bf

File tree

Expand file treeCollapse file tree

8 files changed

+1329
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+1329
-4
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+25Lines changed: 25 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,31 @@ multiple of the element size.
13861386
While calling `napi_create_typedarray()`, `(length * size_of_element) +
13871387
byte_offset` was larger than the length of given `buffer`.
13881388

1389+
<a id="ERR_NAPI_TSFN_CALL_JS"></a>
1390+
### ERR_NAPI_TSFN_CALL_JS
1391+
1392+
An error occurred while invoking the JavaScript portion of the thread-safe
1393+
function.
1394+
1395+
<a id="ERR_NAPI_TSFN_GET_UNDEFINED"></a>
1396+
### ERR_NAPI_TSFN_GET_UNDEFINED
1397+
1398+
An error occurred while attempting to retrieve the JavaScript `undefined`
1399+
value.
1400+
1401+
<a id="ERR_NAPI_TSFN_START_IDLE_LOOP"></a>
1402+
### ERR_NAPI_TSFN_START_IDLE_LOOP
1403+
1404+
On the main thread, values are removed from the queue associated with the
1405+
thread-safe function in an idle loop. This error indicates that an error
1406+
has occurred when attemping to start the loop.
1407+
1408+
<a id="ERR_NAPI_TSFN_STOP_IDLE_LOOP"></a>
1409+
### ERR_NAPI_TSFN_STOP_IDLE_LOOP
1410+
1411+
Once no more items are left in the queue, the idle loop must be suspended. This
1412+
error indicates that the idle loop has failed to stop.
1413+
13891414
<a id="ERR_NO_CRYPTO"></a>
13901415
### ERR_NO_CRYPTO
13911416

Collapse file

‎doc/api/n-api.md‎

Copy file name to clipboardExpand all lines: doc/api/n-api.md
+373-1Lines changed: 373 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Large diffs are not rendered by default.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.