Julia Tasks & Timeouts

Illustration of a computer network. For decoration.
Illustration: Computer Network Basics. IP of i-netsolutions.net.

The Scenario

The Problem

The Solution

payload_task = @async begin
sleep(10)
println("deferred!")
end
timeout_task = @async begin
sleep(5)
schedule(payload_task, "cancel", error=true)
end
wait(payload_task)

The Plug

using ExtraFuntask = with_cancel() do
sleep(10)
println("I should never be reached")
end
if some_condition
cancel(task)
else
wait(task)
end
task = with_timeout(5) do
sleep(10)
println("I should timeout after 5s")
end
wait(task)

Freelance Software Engineer | DLT/Blockchain Enthusiast & Future Entrepreneur

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store