Creează un cont pentru a te abona la acest blog și a-i urmări articolele pe pagina Lectură.
-
Since Go 1.23, we’ve had a new way we can implement iterators.
-
Until recently, custom iterators were probably the most common way to iterate over a list of elements that might trigger an error.
-
For this discussion of iterators, let’s establish a baseline example.
-
I’m going to change gears from the previous discussion about goroutines, to different ways of iterating.
-
Last time I introduced the SetLimit feature of the errgroup package.
-
The errgroup package we’ve been looking at lately has one more trick up its sleeve: Limiting the number of running goroutines.
-
I’m sorry for the delay in writing.
-
Join me later today at 3:00pm EDT (19:00 UTC), for more live coding.
-
Join me tomorrow, August 29, at 3:00pm EDT (19:00 UTC), for more live coding.
-
Join me today, August 22, at 3:00pm EDT (19:00 UTC), more live coding.
-
Join me again, this coming Friday, August 22, at 3:00pm EDT (19:00 UTC), more live coding.
-
Can you spot the mistake in this code?
-
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.
-
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.
-
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.
-
It’s been a year since my last live stream, as I was moving across the globe.
-
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.
-
Today I’m starting a new series of posts on the topic of goroutines.
-
Today I want to share a trick I stumbled upon.
-
I’ve been on vacation for the last week, so haven’t written much.
-
This is it!
-
func WithValue func WithValue(parent Context, key, val any) Context WithValue returns a derived context that points to the parent Context.
-
We’re almost done going through the context package.
-
After this detour through context key types, let’s get back to the GoDoc for our context package.
-
So we’ve finally settled on a suitable type for our context key types: string, or maybe a non-empty struct.
-
First, a correction!
-
First off, an apology for being rather unreliable with my “daily” emails.
-
By now we’ve looked at empty structs (struct{}), and integers as possible context key types.
-
We’re looking at different types for context keys.
-
So we’ve established that context keys should be of an unexported type in your package.
-
Last week we saw the potential dangers of context key collisions.
-
Let’s talk about keys for context values. type Context type Context interface { … // A key identifies a specific value in a Context.
-
I’ve already talked a bit about context values, and when not to use them.
-
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…
-
May I rant for a moment?
-
On Friday we looked at the context.Context interface as a whole.
-
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…
-
func WithTimeout func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
-
Today we’re talking about canceling contexts based on time.
-
About a week ago, I talked about the two error types that a context may return: context.Canceled and context.DeadlineExceeded.
-
I’m jumping out of order a bit today, to cover a more basic function first, before the more advanced version.
-
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.
-
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…
-
Overview … The same Context may be passed to functions running in different goroutines; Contexts are safe for simultaneous use by multiple goroutines.
-
Storing values in a context is quite flexible, but comes without strict type safety, and obscures the API.
-
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.
-
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…
-
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.
-
Overview … Do not pass a nil Context, even if a function permits it.
-
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”.