Permalink
Browse files

take account of next_timeout value when processing events

  • Loading branch information...
1 parent aaa7c4a commit 50e7c0b8fe76b252662378c3925dbd6f2fee4d2e @Floby committed Dec 27, 2012
Showing with 15 additions and 3 deletions.
  1. +14 −2 lib/Session.js
  2. +1 −1 src/session.cc
View
@@ -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);
};
/**
View
@@ -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);
}
/**

0 comments on commit 50e7c0b

Please sign in to comment.