Search code examples
javascriptcallbacknpapifirebreath

Callback from FireBreath


In my plugin, i want to start new thread and take callbacks from it:

I have

function myCallback()

and i want to call it every 2 seconds from my thread in plugin.

How can i do it?

// this method calls from html-page:
void MyFirstPluginAPI::testEvent()
{
  //fire_test();
  // thread starting:
  boost::thread my_thread(boost::bind(&MyFirstPluginAPI::hello_world, this));
}
void MyFirstPluginAPI::hello_world() 
{
  for(;;)
  {
    boost::posix_time::seconds SleepTime(2);
    boost::this_thread::sleep(SleepTime);
    // here i must call InvokeAsync("myCallback",FB::variant_list_of(0));
    // how can i to do it?
  }
}

Thank you very much.


Solution

  • Is it true answer? Is it true async callback from plugin to browser/html-page?

    Maybe, i solved the problem.

    I don't use InvokeAsync, i make 'signal':

    FB_JSAPI_EVENT(event1, 0, ());
    

    then i emit 'signal'

    fire_event1();
    

    and i receive 'signal' on site

    addEvent(plugin(), 'event1', function(){
      elem = document.getElementById('mydiv');
      elem.innerHTML = elem.innerHTML + "hello<br>";
    });
    

    I will test this any time, and then i will mark this question as solved.