savo.la

2022-10-22

Go code snippets

A little copying is better than a little dependency.

Get a pointer to a literal

func ptr[T any](x T) *T {
	return &x
}

Coalesce asynchronous wake-ups

// poke a buffered channel.
func poke(c chan<- struct{}) {
	select {
	case c <- struct{}{}:
	default:
	}
}
Placed in the public domain by Timo Savola