title: How do I save a callback for later with node-addon-api?
body: <p>I want my C library to be able to call a JS function multiple times.  I got it to work using Nan but am having trouble converting it to N-API/node-addon-api.</p>
  
  <p>How do I save a JS callback function and call it later from C?</p>
  
  <p>Here's what I have using Nan:</p>
  
  <pre><code>Persistent&lt;Function&gt; r_log;
  void sendLogMessageToJS(char* msg) {
      if (!r_log.IsEmpty()) {
          Isolate* isolate = Isolate::GetCurrent();
          Local&lt;Function&gt; func = Local&lt;Function&gt;::New(isolate, r_log);
          if (!func.IsEmpty()) {
          const unsigned argc = 1;
          Local&lt;Value&gt; argv[argc] = {
              String::NewFromUtf8(isolate, msg)
          };
          func-&gt;Call(Null(isolate), argc, argv);
          }
      }
  }
  NAN_METHOD(register_logger) {
      Isolate* isolate = info.GetIsolate();
      if (info[0]-&gt;IsFunction()) {
          Local&lt;Function&gt; func = Local&lt;Function&gt;::Cast(info[0]);
          Function * ptr = *func;
          r_log.Reset(isolate, func);
          myclibrary_register_logger(sendLogMessageToJS);
      } else {
          r_log.Reset();
      }
  }
  </code></pre>
  
  <p>How do I do the equivalent with node-addon-api?  All the examples I've seen immediately call the callback or use AsyncWorker to somehow save the callback.  I can't figure out how AsyncWorker is doing it.</p>