Catch exception.
This commit is contained in:
parent
279e9f04cc
commit
8f707b34b1
3 changed files with 38 additions and 24 deletions
25
lib/Curl.js
25
lib/Curl.js
|
@ -1,6 +1,6 @@
|
|||
// Generated by ToffeeScript 1.4.0
|
||||
(function() {
|
||||
var Curl, id, m, p;
|
||||
var Curl, curls, id, m, p;
|
||||
|
||||
try {
|
||||
Curl = require(__dirname + '/../build/Release/node-curl').Curl;
|
||||
|
@ -53,16 +53,29 @@
|
|||
DEBUG: 'DEBUG'
|
||||
};
|
||||
|
||||
id = 0;
|
||||
|
||||
curls = {};
|
||||
|
||||
Curl.prototype.on = function(event, callback) {
|
||||
var _this = this;
|
||||
switch (event) {
|
||||
case 'data':
|
||||
this.on_write = callback;
|
||||
this.on_write = function(chunk) {
|
||||
return callback.call(_this, chunk);
|
||||
};
|
||||
break;
|
||||
case 'error':
|
||||
this.on_error = callback;
|
||||
this.on_error = function(e) {
|
||||
delete curls[_this.id];
|
||||
return callback.call(_this, e);
|
||||
};
|
||||
break;
|
||||
case 'end':
|
||||
this.on_end = callback;
|
||||
this.on_end = function() {
|
||||
delete curls[_this.id];
|
||||
return callback.call(_this);
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new Error("invalid event type " + event);
|
||||
|
@ -71,13 +84,13 @@
|
|||
};
|
||||
|
||||
Curl.prototype.close = function() {
|
||||
delete curls[this.id];
|
||||
return this.close_();
|
||||
};
|
||||
|
||||
id = 0;
|
||||
|
||||
Curl.prototype.perform = function() {
|
||||
this.id = ++id;
|
||||
curls[this.id] = this;
|
||||
this.perform_();
|
||||
Curl.process();
|
||||
return this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue