Skip to content

Instantly share code, notes, and snippets.

@hotafrika
Created November 9, 2022 11:17
Show Gist options
  • Save hotafrika/dcbae89bf74a0ad9bd4536cffd4e7178 to your computer and use it in GitHub Desktop.
Save hotafrika/dcbae89bf74a0ad9bd4536cffd4e7178 to your computer and use it in GitHub Desktop.
medium / singleflight
type NodeStat struct {
// NodeData []byte // omit it for this example
NodeID string
Timestamp time.Time
}
type App struct {}
func (a *App) GetNodeStatSync(nodeID string) (*NodeStat, error) {
collectedAt := time.Now()
// Add some time for workload emulation.
time.Sleep(10 * time.Second)
return &NodeStat{
NodeID: nodeID,
Timestamp: collectedAt,
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment