Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created April 27, 2013 09:18
Show Gist options
  • Save fengmk2/5472462 to your computer and use it in GitHub Desktop.
Save fengmk2/5472462 to your computer and use it in GitHub Desktop.
遍历map之前先重置
Connection.prototype._cleanupCalls = function (err) {
  var count = 0;
  var calls = this.calls;
  this.calls = {}; // should reset calls before traverse it.
  for (var id in calls) {
    var call = calls[id];
    call.setException(err);
    count++;
  }
  // this.calls = {};
  debug('conn#%d: clenaup %d calls, send "%s:%s" response.', this.id, count, err.name, err.message);
};
@fengmk2
Copy link
Author

fengmk2 commented Apr 27, 2013

setException会触发一个callback,然后callback里面的一些代码,又会触发_cleanupCalls,然后就杯具发生了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment