Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some reference material on golang Context #187

Open
illicitonion opened this issue Apr 14, 2024 · 2 comments
Open

Add some reference material on golang Context #187

illicitonion opened this issue Apr 14, 2024 · 2 comments
Assignees

Comments

@illicitonion
Copy link
Member

Both of our Cohort 2 trainees have raised existential questions around Context. We may want to find some useful references or write up some material about this.

We may even want to make a "implement WithTimeout using WithValue" exercise to show that there's no magic here, it's really just a fancy key-value store.

(I've also gone on a tangent around persistent data structures when talking through this, unclear whether that's actually useful/worthwhile :))

@illicitonion
Copy link
Member Author

The journey I've typically used to explain this is:

  • We know about dependency injection, when people take dependency injection to extremes they end up with too many parameters, they often extract a context object to contain them all (prompt discussion about global state, about the down-sides of God objects, ...).
  • Context is a place to shove global-like data that we want to use a lot of places. But we generally shouldn't.
  • Introduce With-prefixed functions (and maybe contrast with other persistent data structures / builders / ...)
  • Talk through WithValue with a user ID as an example
  • Talk through WithTimeout and Done as just a library written using WithValue.

@bazmurphy had also encountered React's Context hooks which implement a similar pattern.

@lauranooooo lauranooooo self-assigned this Apr 15, 2024
@lauranooooo
Copy link
Contributor

that is a good thought, IMO.
I am sure we must be using timeout somewhere. we certainly have material on the need for timeouts in the primer, don't we?
i think we could probably weave this into at least one of the exercises. maybe with some explicit demos of client cancellation as well, and a description of why that's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants