Context in the standard library

Now that we've covered the contents of the package, we will look at how to use them with the standard package or in an application. Context is used in a few functions and methods of standard packages, mostly network packages. Let's go over them now:

  • http.Server uses it with the Shutdown method so that it has full control over timeout or to cancel an operation.
  • http.Request allows you to set a context using the WithContext method. It also allows you to get the current context using Context.
  • In the net package, Listen, Dialand Lookup have a version that uses Context to control deadlines and timeouts.
  • In the database/sql package, context is used to stop or timeout many different operations.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.35.194