3 ms·
This problem seems similar to processing a request that has a deadline, after which the request is discarded and any resources should be freed. In Go, you can
by skybrian 8y ago
This problem seems similar to processing a request that has a deadline, after which the request is discarded and any resources should be freed.
In Go, you can keep track of deadlines using a Context [1]. Subrequests also need to know the deadline (or perhaps a shorter deadline), so they get passed a derived context. The same mechanism also supports cancellation.
[1] https://golang.org/pkg/context/ https://golang.org/pkg/context/
- rumcajz 8y agoIt was proposed to introduce structured concurrency to Go, but it's not easy, not least because of the context and how it would play along. The issue was closed with "we need a larger discussion" comment. https://github.com/golang/go/issues/29011 https://github.com/golang/go/issues/29011 If you are interested in that you may want to participate.
- latchkey 8y agoI deployed a binary golang agent [1] across about 2000 raspberry pi class machines (for litecoin mining) using overseer [2]. It allowed me to implement zero downtime upgrades, which was pretty cool. Internally within the agent, I used the context pkg to implement with a 'Manager' which provided cron like functionality where each thing could be shutdown gracefully [3]. Used the same mechanism to shut the internal webserver down gracefully as well [4]. [1] https://github.com/jpillora/overseer https://github.com/jpillora/overseer [2] https://github.com/blockassets/bam_agent https://github.com/blockassets/bam_agent [3] https://github.com/blockassets/bam_agent/blob/f7edce599b770b26189fd2c2fbb7cff81ac827a6/monitor/manager.go#L53 https://github.com/blockassets/bam_agent/blob/f7edce599b770b... [4] https://github.com/blockassets/bam_agent/blob/f7edce599b770b26189fd2c2fbb7cff81ac827a6/web_server.go#L50 https://github.com/blockassets/bam_agent/blob/f7edce599b770b...