← Înapoi la Urmăritori

Cel mai recent articol

Ultima verificare

Urmăritori 0 urmăritori
Articole: 200
  1. Range over func

    Since Go 1.23, we’ve had a new way we can implement iterators.

  2. Custom iterators

    Until recently, custom iterators were probably the most common way to iterate over a list of elements that might trigger an error.

  3. For this discussion of iterators, let’s establish a baseline example.

  4. Iterator patterns

    I’m going to change gears from the previous discussion about goroutines, to different ways of iterating.

  5. Last time I introduced the SetLimit feature of the errgroup package.

  6. Limiting goroutines

    The errgroup package we’ve been looking at lately has one more trick up its sleeve: Limiting the number of running goroutines.

  7. I’m sorry for the delay in writing.

  8. Join me later today at 3:00pm EDT (19:00 UTC), for more live coding.

  9. Join me tomorrow, August 29, at 3:00pm EDT (19:00 UTC), for more live coding.

  10. Join me today, August 22, at 3:00pm EDT (19:00 UTC), more live coding.

  11. Join me again, this coming Friday, August 22, at 3:00pm EDT (19:00 UTC), more live coding.

  12. Can you spot the mistake in this code?

  13. Go 1.25 is here!

    Join me tomorrow, Friday, August 15, at 3:00pm EDT (19:00 UTC), for a live stream where I’ll be building a new feature in my open-source project.

  14. Dynamic wait groups

    Join me this Friday, August 15, at 3:00pm EDT (19:00 UTC), for a live stream where I’ll be building a new feature in my open-source project.

  15. WaitGroup shortcuts

    Join me next Friday, at 3:00pm EDT (19:00 UTC), for a live stream where I’ll be building a new feature in my open-source project.

  16. sync.WaitGroup

    It’s been a year since my last live stream, as I was moving across the globe.

  17. Yesterday we looked at some sample code with goroutines: for i := range 10 { go func() { fmt.Println(i) }() } But if you ran it, you probably saw no output.

  18. Goroutines

    Today I’m starting a new series of posts on the topic of goroutines.

  19. Dependency pinning

    Today I want to share a trick I stumbled upon.

  20. I’ve been on vacation for the last week, so haven’t written much.

  21. context.WithoutCancel

    This is it!

  22. context.WithValue

    func WithValue func WithValue(parent Context, key, val any) Context WithValue returns a derived context that points to the parent Context.

  23. context.TODO

    We’re almost done going through the context package.

  24. context.Background

    After this detour through context key types, let’s get back to the GoDoc for our context package.

  25. So we’ve finally settled on a suitable type for our context key types: string, or maybe a non-empty struct.

  26. First, a correction!

  27. Struct context keys

    First off, an apology for being rather unreliable with my “daily” emails.

  28. String context keys

    By now we’ve looked at empty structs (struct{}), and integers as possible context key types.

  29. Integer context keys

    We’re looking at different types for context keys.

  30. Context key types

    So we’ve established that context keys should be of an unexported type in your package.

  31. Last week we saw the potential dangers of context key collisions.

  32. Let’s talk about keys for context values. type Context type Context interface { … // A key identifies a specific value in a Context.

  33. Context values

    I’ve already talked a bit about context values, and when not to use them.

  34. Context errors

    type Context type Context interface { … // If Done is not yet closed, Err returns nil. // If Done is closed, Err returns a non-nil error explaining why: // DeadlineExceeded if the context's deadline passed, // or Canceled if the context was canceled for s…

  35. The Done channel

    May I rant for a moment?

  36. Context deadlines

    On Friday we looked at the context.Context interface as a whole.

  37. Today we come to the core of the context package: The Context interface itself. type Context type Context interface { Deadline() (deadline time.Time, ok bool) Done() <-chan struct{} Err() error Value(key any) any } A Context carries a deadline, a cancella…

  38. func WithTimeout func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).

  39. Today we’re talking about canceling contexts based on time.

  40. Context causes

    About a week ago, I talked about the two error types that a context may return: context.Canceled and context.DeadlineExceeded.

  41. Canceling a context

    I’m jumping out of order a bit today, to cover a more basic function first, before the more advanced version.

  42. AfterFunc

    One of the drawbacks of this format I’ve chosen—reading through a document, and providing commentaty, in order—is that sometimes advanced topics come up before the foundational ones they rely on.

  43. The context package exports two variables: Variables var Canceled = errors.New("context canceled") Canceled is the error returned by [Context.Err] when the context is canceled for some reason other than its deadline passing. var DeadlineExceeded error = d…

  44. Overview … The same Context may be passed to functions running in different goroutines; Contexts are safe for simultaneous use by multiple goroutines.

  45. Storing values in a context is quite flexible, but comes without strict type safety, and obscures the API.

  46. Last week I asked whether or not it’s a good idea to pass things like a user-scoped database handle or logger via a context value.

  47. Context abuse

    We’re nearly through the overview of the context package, when we come across this seemlingly straightforward sentence: Overview … Use context Values only for request-scoped data that transits processes and APIs, not for passing optional parameters to fun…

  48. T.Context

    After my last email, discussing context.TODO(), I got this question from Bruno Schaatsbergen: Thanks for the blog Jonathan, as always a pleasure to read.

  49. context.TODO

    Overview … Do not pass a nil Context, even if a function permits it.

  50. Context arguments

    Overview … The Context should be the first parameter, typically named ctx: func DoSomething(ctx context.Context, arg Arg) error { // ... use ctx ... } This short sentence includes two “rules”.