Skip to content

Multiple ctx created from context.Background() #37

Answered by benbjohnson
lobre asked this question in Q&A
Discussion options

You must be logged in to vote

Good question. The context is typically request-based so it's generated from the HTTP server and that's what's used for most of the code in wtf. Typically the exception is background processing like what the sqlite.DB.monitor() function is doing.

The reason I like to manage an internal context for DB instead of using one from main() is that it lets me control the shutdown process better. For example, I typically want to wait for the signal from the OS to shutdown and then shutdown the HTTP server and then shutdown the DB. That allows me to gracefully close open connections on the HTTP server whereas closing the DB first would immediately return errors on open connections.

If you pass a ca…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lobre
Comment options

@lobre
Comment options

@benbjohnson
Comment options

Answer selected by benbjohnson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants