Skip to content
Discussion options

You must be logged in to vote

You don't call it from your own Tokio code: rust-anything ports are called from the original language (JS, Python, etc.), through the generated bindings.

  • JS: if the original function is async (or returns a Promise), the port is a pub async fn and JS gets a Promise back. napi-rs runs it on its own async runtime, so it doesn't block Node's event loop.
  • A sync port runs on the caller's thread like any native call. For long CPU work, make the export async (and use spawn_blocking inside it if you like), or move the whole loop with --batch.
  • Python ports are sync today.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nezuko35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants