diff --git a/lib/Session.js b/lib/Session.js index dfeaa55..23e2f0a 100644 --- a/lib/Session.js +++ b/lib/Session.js @@ -135,11 +135,23 @@ Session.prototype._setupNativeCallbacks = function _setupNativeCallbacks() { * TODO ^ */ Session.prototype._startProcessingEvents = function _startProcessingEvents() { + this._sp_session.notify_main_thread = sessionCallback(this, function() { + if(this.isClosed()) return; + clearTimeout(this._process_events_timeout); + this._scheduleProcessingEvents(1); + }) if(this._process_events_timeout) return; + this._scheduleProcessingEvents(10); +}; + +Session.prototype._scheduleProcessingEvents = function _scheduleProcessingEvents(timeout) { var self = this; - this._process_events_timeout = setInterval(sessionCallback(this, function() { + this._process_events_timeout = setTimeout(sessionCallback(this, function() { var next_timeout = b.session_process_events(self._sp_session); - }), 1500); + if(this.isClosed()) return; + clearTimeout(self._process_events_timeout); + self._scheduleProcessingEvents(next_timeout); + }), timeout); }; /** diff --git a/src/session.cc b/src/session.cc index 7d41df0..7da6640 100644 --- a/src/session.cc +++ b/src/session.cc @@ -130,7 +130,7 @@ static void call_notify_main_thread_callback(sp_session* session) { // set the loop to call our JS callback in 3 ms // TODO how about next tick ? - uv_timer_start(&do_notify_handle, &do_call_notify_main_thread_callback, 3, 0); + uv_timer_start(&do_notify_handle, &do_call_notify_main_thread_callback, 1, 0); } /**