Skip to content

Commit

Permalink
so that we could set a different backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
godfat committed Jan 5, 2015
1 parent 30606b4 commit 35812df
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/rest-core/promise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def defer
end
end
# set timeout after thread/task set
env[TIMER].on_timeout{ cancel_task } if env[TIMER]
env[TIMER].on_timeout{ cancel_task(backtrace) } if env[TIMER]
end
end

Expand Down Expand Up @@ -207,14 +207,18 @@ def callback_error e
end
end

def cancel_task
def cancel_task backtrace=nil
mutex.synchronize do
next if done? # don't cancel if it's done
if t = thread || task.thread
t.raise(env[TIMER].error) # raise Timeout::Error to working thread
else # task was queued and never started, just cancel it and
task.cancel # fulfil the promise with Timeout::Error
rejecting(env[TIMER].error)
else # task was queued and never started, just cancel it and
begin # fulfil the promise with Timeout::Error
task.cancel
rejecting(env[TIMER].error)
rescue Exception => e # log user callback error
callback_error(e){e.set_backtrace(e.backtrace + (backtrace || []))}
end
end
end
end
Expand Down

0 comments on commit 35812df

Please sign in to comment.