Skip to content

Instantly share code, notes, and snippets.

@terasakisatoshi
Created February 2, 2025 04:36
Show Gist options
  • Save terasakisatoshi/ca7c1fd349b4af1630d0f6a047f37828 to your computer and use it in GitHub Desktop.
Save terasakisatoshi/ca7c1fd349b4af1630d0f6a047f37828 to your computer and use it in GitHub Desktop.
task in the while loop
function main()
c = 0
while true
c += 1
@info "c" c
t = @async begin
try
sleep(1)
if c >= 5
@show x
end
return :done
catch e
if e isa InterruptException
@info "Exit"
return :interrupted
else
rethrow(e)
end
end
end
wait(t)
status = fetch(t)
if status === :done
@info "Done"
continue
end
if status === :interrupted
@info "stopped"
break
end
if istaskfailed(t)
throw(TaskFailedException())
end
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment