Improve performance.

This commit is contained in:
Miao Jiang 2013-02-19 20:54:47 +08:00
parent 02ba0f25d3
commit 1061e177b2
6 changed files with 29 additions and 9 deletions

View file

@ -62,14 +62,24 @@ Curl::perform = ->
Curl.process()
@
m = 0
p = console.log
Curl.process = ->
if Curl.in_process
return
do once = ->
num = Curl.process_()
if num > 0
n = Curl.process_()
if n > 0
Curl.in_process = true
setTimeout once, 80
if n > 8192 && m < 10
++m
process.nextTick once
else
m = 0
w = (8192 - n) * 80 / 8192
if w < 0
w = 0
setTimeout once, w
else
Curl.in_process = false

View file

@ -35,6 +35,7 @@
curl = function() {
return curl.perform.apply(curl, arguments);
};
curl.Curl = Curl;
curl.perform = function() {
var args, c, cb, k, length, v, _ref, _ref1, _ref2, _ref3, _ref4;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];

View file

@ -16,6 +16,7 @@ class CurlBuilder
curl = ->
curl.perform.apply curl, arguments
curl.Curl = Curl
curl.perform = (args...) ->
if @running
throw new Error 'the cURL session is busy, use curl.create to create another cURL Session'