既然可以开启一个协程,我好想在文档里看不到怎么取消一个协程,有哪位能告诉我怎么做到
julia> t=@async begin
try
sleep(5)
println("buzz")
catch ex
#println(ex)
end
end
Task (runnable) @0x00000000138b6e10
julia> schedule(t,InterruptException();error=true)
Task (done) @0x00000000138b6e10
这个看起来好像是给这个任务一个错误信号让他强制退出,很暴力的样子,有没有温柔点的方法
ps: 其他语言的协程没怎么接触过
julia> stop=false
false
julia> t=@async begin
while !stop
println("buzz")
sleep(3)
end
end
buzz
Task (runnable) @0x000000011c691d50
julia> stop=true
true