[quickjs-devel] Re: GC and async JS question

  • From: Saúl Ibarra Corretgé <s@xxxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Thu, 23 Jan 2020 11:27:13 +0100

On 23/01/2020 03:59, JM wrote:

I have a custom class that does  async operations. I like to understand
when does GC fires and cleans up variables, how to prevent GC from
cleaning the variable which is doing async operation and then once again
enable GC after the async task is over.

Here is the complete script. I would like to GC to preserve the variable
'task' till the async task is executing. However, after onDone is
called, GC is free to take whatever action necessary.  

var task = new AsyncTask; 
task.data  = "some data";
task.onDone = function(task) {


task.execute();

Please suggest.

You should be able to accomplish this by adding an extra reference on
the constructor (JS_DupValue before you return). Then when done
JS_FreeValue.

-- 
Saúl

Other related posts: