Catch exception.
This commit is contained in:
parent
279e9f04cc
commit
8f707b34b1
3 changed files with 38 additions and 24 deletions
|
@ -42,28 +42,37 @@ Curl.user_options =
|
|||
RAW: 'RAW'
|
||||
DEBUG: 'DEBUG'
|
||||
|
||||
id = 0
|
||||
curls = {}
|
||||
|
||||
# on 'data' must be returns the chunk length
|
||||
Curl::on = (event, callback) ->
|
||||
switch event
|
||||
when 'data'
|
||||
# (Buffer chunk) ->
|
||||
@on_write = callback
|
||||
@on_write = (chunk) =>
|
||||
callback.call @, chunk
|
||||
when 'error'
|
||||
# (Error error) ->
|
||||
@on_error = callback
|
||||
@on_error = (e) =>
|
||||
delete curls[@id]
|
||||
callback.call @, e
|
||||
when 'end'
|
||||
# () ->
|
||||
@on_end = callback
|
||||
@on_end = =>
|
||||
delete curls[@id]
|
||||
callback.call @
|
||||
else
|
||||
throw new Error("invalid event type #{event}")
|
||||
@
|
||||
|
||||
Curl::close = () ->
|
||||
delete curls[@id]
|
||||
@close_()
|
||||
|
||||
id = 0
|
||||
Curl::perform = ->
|
||||
@id = ++id
|
||||
curls[@id] = @
|
||||
@perform_()
|
||||
Curl.process()
|
||||
@
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue