Skip to content

The trait Send is not implemented: how to use boa in async threaded context best? #3093

Closed Answered by jedel1043
k-bx asked this question in Q&A
Discussion options

You must be logged in to vote

Short answer: Please use tokio::task::spawn_local instead.

Long answer: The JS execution model pretty much restricts all implementors of the spec to be single-threaded (with respect to the interpreter, but there are other ways to share work between threads like Workers), which is why Boa extensively uses !Send types and thread locals to maximize performance.

A Boa context is local to the current thread, so if you want to wrap it in a tokio task, you'll need to use the capabilities of tokio to run !Send futures: task::spawn for simple tasks and LocalSet for task groups.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by k-bx
Comment options

You must be logged in to vote
0 replies
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