如何杀死朱莉娅的任务/协同程序?

Nic*_*ick 15 task coroutine julia

using HttpServer

http = HttpHandler() do request::Request, response::Response
    show(request)
    Response("Hello there")
end

http.events["error"] = (client, error) -> println(error)
http.events["listen"] = (port) -> println("Listening on $port")
server = Server(http)

t = @async run(server, 3000)
Run Code Online (Sandbox Code Playgroud)

这会异步启动一个简单的小型Web服务器.问题是我不知道如何阻止它.我已经经历了朱莉娅的文件,并试图找到一些功能将会从队列(删除此任务kill,interrupt等),但似乎没有任何工作.

我怎么能杀掉这个任务?

los*_*der 9

我没有看到专门结束任务的官方方法,但我认为通用解决方案是添加了throwto,它允许您立即安排具有待处理异常的任务.

...
t = @async run(server, 3000)
...
ex = InterruptException()
Base.throwto(t, ex)
close(http.sock) # ideally HttpServer would catch exception to cleanup
Run Code Online (Sandbox Code Playgroud)