proxy.golang.org : github.com/lestrrat-go/simple-guard
Package guard provides a simple construct to help you write a RAII-like construct in Go. Go doesn't provide a deterministic way to fire code at garbage collection time, but you can sort of do it when `defer` gets fired. The guard package gives you one more additional layer of functionality. For example, if you're doing a database operation, you might want to register a `Rollback()` call, only to make sure that in case you return before committing, you make sure your previous operations are discarded: Except, if the operation is successful, you will be calling `Commit()` and then `Rollback()`, which causes an error. So you would need to keep track if you have actually called `Commit()` This is doable, but you probably don't want to do that all over the place. This is where this package comes in. The `Guard` interface specifies `Fire()` and `Cancel()`, which makes the above construct easier: Once `Fire()` or `Cancel()` is called, the Guard never fires again, so you can safely use it both in the success and failure cases. Please also see: https://github.com/lestrrat-go/tx-guard
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/lestrrat-go/simple-guard
License: MIT
Latest release: about 7 years ago
First release: about 7 years ago
Namespace: github.com/lestrrat-go
Stars: 0 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 2 months ago