Created
February 2, 2025 04:36
-
-
Save terasakisatoshi/ca7c1fd349b4af1630d0f6a047f37828 to your computer and use it in GitHub Desktop.
task in the while loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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