DelSkayn / rquickjs

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

How to call runtime.run_gc() from js? #255

Closed richarddd closed 2 months ago

richarddd commented 5 months ago

Hi,

Is it any way to run gc from js? I currently have the code bellow, but since i wait for completion using: runtime.idle().await it holds a lock on the runtime meaning that below function will block waiting for that lock.

ctx.globals().set(
      "__gc",
      Func::from(Async(move || {
          let runtime = rt2.clone();
          async move {
              runtime.run_gc().await;
          }
      })),
  )?;
richarddd commented 5 months ago

Found a work around by unsafely access the current runtime:

 unsafe {
        let rt = qjs::JS_GetRuntime(ctx.as_raw().as_ptr());
        qjs::JS_RunGC(rt);
    };