Skip to content

Commit

Permalink
take account of next_timeout value when processing events
Browse files Browse the repository at this point in the history
  • Loading branch information
Floby committed Dec 27, 2012
1 parent aaa7c4a commit 50e7c0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/Session.js
Expand Up @@ -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);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/session.cc
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 50e7c0b

Please sign in to comment.