DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
434 stars 59 forks source link

Async context doesn't seem to implement Send or Sync #234

Closed ezenkico closed 7 months ago

ezenkico commented 8 months ago

I'm attempting to use async_with! and am having some issues when send and sync are required.

I'm getting the following errors:

NonNull<JSContext>` cannot be shared between threads safely`
`future cannot be sent between threads safely
within `rquickjs_core::runtime::raw::RawRuntime`, the trait `std::marker::Send` is not implemented for `NonNull<rquickjs_sys::JSRuntime>

here is the code in the function that is causing this

let rt = match AsyncRuntime::new(){
      Ok(rt) => rt,
      Err(e) => return Err(invalid_data(format!("{e}")))
    };

    let ctx = match AsyncContext::full(&rt).await{
      Ok(ctx) => ctx,
      Err(e) => return Err(invalid_data(format!("{e}")))
    };

It doesn't show errors when the function just contains this

let rt = match AsyncRuntime::new(){
      Ok(rt) => rt,
      Err(e) => return Err(invalid_data(format!("{e}")))
    };
DelSkayn commented 7 months ago

By default AsyncRuntime and AsyncContext don't implement send and sync. Have you enabled the parallel feature on the crate? That should implement send and sync for both structs.

ezenkico commented 7 months ago

That seemed to work.

Sorry for the dumb question.

I appreciate the help.

Thanks