0x4b53 / amqp-rpc

🐰 Framework to use RabbitMQ as RPC
MIT License
45 stars 8 forks source link

HandlerFunc ctx is .Done() when server is stopped #87

Closed akarl closed 4 years ago

akarl commented 4 years ago

User can now check ctx.Done() inside a handler to be able to abort and cleanup when a server wants to shut down.

func MyHandler(ctx context.Context, rw *ResponseWriter, d amqp.Delivery) {
    for {
        // ...
        // Some long running thingy.
        // ...

        select {
        case <-ctx.Done():
            // Server wants to stop. Do some cleanup and return.
            doCleanup()
            return
        }
    }
}

(One commit fixes some linting, check just the last commit if you only want to look at the Context changes).

codeclimate[bot] commented 4 years ago

Code Climate has analyzed commit c06b33db and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 88.6%.

View more on Code Climate.