go-context

A simply tryout of how contexts work in golang

The example here executes four faked API calls, that take x seconds to execute (see the apiCallExecutionTime constant)

It gets executed:

  1. with the regular context timeout value
  2. with a detached context (that ignores the default timeout value of the parent context)
  3. with a detached context but with an extended timeout value (still below the API’s response time)
  4. wiht a detached context and an extended timeout value above the API’s response time

The expected results here are a “context deadline exceeded” error for usecases 1 and 3, and successful response for usecases 2 and 4

GitHub

View Github