- Use generics to create RPC call wrappers.
- Demonstrate a basic JSON-RPC 2.0 client and server.
- Editing regular expressions before compilation.
- Transmitting a pointer via a byte buffer.
- Composing functions with errors. Requires Go ≥ 1.18.
- Example using the
jtreelibrary. - Decorating JSON values with comments.
| package main_test | |
| import ( | |
| "fmt" | |
| "testing" | |
| ) | |
| func BenchmarkBuf(b *testing.B) { | |
| for _, bs := range []int{0, 1, 2, 10, 32} { | |
| b.Run(fmt.Sprint(bs), func(b *testing.B) { |
When multiple goroutines share access to a value that will periodically change, readers may wish to wait for a value to be updated before reading the value again. This can be solved using a condition variable:
var val *Thing
var mu = new(sync.Mutex)
var cond = sync.NewCond(mu)
func wait(old *Thing) *Thing {| #!/bin/zsh | |
| set -euo pipefail | |
| readonly pollsec=5 | |
| if [[ "$#" = 0 ]] ; then | |
| echo "Missing required run ID" 1>&2 | |
| exit 2 | |
| fi |
Extracted from the Google form posted in https://twitter.com/hammard_1987/status/1449453485343318025.
- Children of Time (Adrian Tchaikovsky)
- Rite of Passage (Alexei Panshin)
- The Demolished Man (Alfred Bester)
- The Calcutta Chromosome (Amitav Ghosh)
- Ancillary Justice (Ann Leckie)
- Dreams Before the Start of Time (Anne Charnock)
Often you have an object that is waiting for some result, e.g., an error to be delivered (once) by some goroutine. Multiple goroutines would like to wait for that to happen.
A traditional solution uses a condition variable, e.g.,
var result value
var ready bool
var mu sync.Mutex(see also: https://godoc.org/github.com/creachadair/msync#Collector)
Many Go APIs allow multiple concurrent writers to a single channel, for example, to enqueue work for a task-processing API. When we do this, there is a tricky question of how to safely close the channel. Because this is tricky, many APIs do not bother, which complicates cleanup for the reader side of the channel. Dave Cheney has a good survey of channel corners that I recommend to anyone who knows Go well enough to be working in this space.
The basic problem is that writing to a closed channel triggers a panic. If some writer can detect that it is the "last", it can close the channel itself -- however that is often not practical unless all the writers are fully under the control of the API itself.
I have found a useful tactic for dealing with this situation.
Algorithm notes from
A. Limasset, G. Rizk, Rr. Chikhi, and P. Peterlongo: Fast and scalable minimal perfect hashing for massive key sets https://arxiv.org/pdf/1702.03154.pdf.
The goal of this algorithm is to create a conflict-free hash of the keys in the collection. The strategy is to create a zero-valued bit vector with at least 1 bit per key, and hash each key to a position in that vector. Any key that hashes uniquely is assigned that position, and removed from the working set.
- https://john-millikin.com/the-fuse-protocol contains lots of detailed links
- libfuse reference implementation