Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #113 and add Inf timeout option #116

Merged
merged 1 commit into from
Nov 15, 2017
Merged

Conversation

samoconnor
Copy link
Contributor

No description provided.

tm = Float64($(esc(t)))
start = time()
tsk = @async $(esc(expr))
yield()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the yield here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per comment in #113, my concern is that istaskdone will return false and cause a 10ms sleep, even if expr would have executed in a very short time. The yield() gives the expr task a chance to run before checking istaskdone.
e.g.

function f()
       t = @async sum([1,2,3])
       !istaskdone(t) && sleep(0.01)
end
julia> f()
julia> @time f()
  0.013942 seconds (12 allocations: 1.031 KiB)

vs

function f()
       t = @async sum([1,2,3])
       yield()
       !istaskdone(t) && sleep(0.01)
end
julia> f()
julia> @time f()
0.000011 seconds (8 allocations: 880 bytes)

sleep($pollint)
end
istaskdone(tsk) || $(esc(then))
wait(tsk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why the change to wait here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because wait rethrows the task exception if needed, whereas the current code ends up at no method matching length(::Base.UVError)

From #113 ...

The timeout macro executes expr in a new task, waits for a timeout or istaskdone, then returns task.result. In the case where expr throws and exception, the exception is returned as a value when it should be re-thrown.

The result is:

ERROR: MethodError: no method matching length(::Base.UVError)
 [1] processresponse!(::HTTP.Client, ::HTTP.Connection{MbedTLS.SSLContext}, ::HTTP.Response, ::String, ::HTTP.Method, ::Task, ::Bool, ::Float64, ::Bool, ::Bool)
at /Users/sam/.julia/v0.6/HTTP/src/client.jl:287

@quinnj quinnj merged commit 779fe74 into JuliaWeb:master Nov 15, 2017
@quinnj
Copy link
Member

quinnj commented Nov 15, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants