{"modulePath":"github.com/GoPlugin/pluginV2Lib/pluginV2-relay","version":"v0.0.0-20230622090102-3f0f60f3c385","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\n## Functions\n\n```go\nfunc BatchSplit[T any](list []T, max int) (out [][]T, err error)\n```\nBatchSplit splits an slices into an slices of slicess with a maximum length\n\n```go\nfunc Context(t *testing.T) context.Context\n```\n\n```go\nfunc ContextFromChan(chStop \u003c-chan struct{}) (context.Context, context.CancelFunc)\n```\nContextFromChan creates a context that finishes when the provided channel receives or is closed. When channel closes, the ctx.Err() will always be context.Canceled NOTE: Spins up a goroutine that exits on cancellation. REMEMBER TO CALL CANCEL OTHERWISE IT CAN LEAD TO MEMORY LEAKS\n\n```go\nfunc ContextWithDeadlineFn(ctx context.Context, deadlineFn func(orig time.Time) time.Time) (context.Context, context.CancelFunc)\n```\nContextWithDeadlineFn returns a copy of the parent context with the deadline modified by deadlineFn. deadlineFn will only be called if the parent has a deadline. The new deadline must be sooner than the old to have an effect.\n\n```go\nfunc GetRandomPort() string\n```\n\n```go\nfunc HashReport(ctx types.ReportContext, r types.Report) ([]byte, error)\n```\nHashReport returns a report digest using SHA256 hash.\n\n```go\nfunc IsPortOpen(t *testing.T, port string) bool\n```\n\n```go\nfunc MustRandomPort(t *testing.T) string\n```\n\n```go\nfunc RawReportContext(repctx types.ReportContext) [3][32]byte\n```\nRawReportContext is a copy of evmutil.RawReportContext to avoid importing go-ethereum. github.com/GoPlugin/pluginV2Lib/libocr/offchainreporting2plus/chains/evmutil#RawReportContext\n\n```go\nfunc WithJitter(d time.Duration) time.Duration\n```\nWithJitter adds +/- 10% to a duration\n\n## Types\n\n```go\ntype Duration struct {\n\t// contains filtered or unexported fields\n}\n```\nDuration is a non-negative time duration.\n\n```go\nfunc MustNewDuration(d time.Duration) *Duration\n```\n\n```go\nfunc NewDuration(d time.Duration) (Duration, error)\n```\n\n```go\nfunc (d Duration) Duration() time.Duration\n```\n\n```go\nfunc (d Duration) MarshalJSON() ([]byte, error)\n```\nMarshalJSON implements the json.Marshaler interface.\n\n```go\nfunc (d Duration) MarshalText() ([]byte, error)\n```\nMarshalText implements the text.Marshaler interface.\n\n```go\nfunc (d *Duration) Scan(v interface{}) (err error)\n```\n\n```go\nfunc (d Duration) String() string\n```\n\n```go\nfunc (d *Duration) UnmarshalJSON(input []byte) error\n```\nUnmarshalJSON implements the json.Unmarshaler interface.\n\n```go\nfunc (d *Duration) UnmarshalText(input []byte) error\n```\nUnmarshalText implements the text.Unmarshaler interface.\n\n```go\nfunc (d Duration) Value() (driver.Value, error)\n```\n\n```go\ntype LazyLoad[T any] struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewLazyLoad[T any](f func() (T, error)) *LazyLoad[T]\n```\n\n```go\nfunc (l *LazyLoad[T]) Get() (out T, err error)\n```\n\n```go\nfunc (l *LazyLoad[T]) Reset()\n```\n\n```go\ntype StartStopOnce struct {\n\tsync.RWMutex // lock is held during startup/shutdown, RLock is held while executing functions dependent on a particular state\n\t// contains filtered or unexported fields\n}\n```\nStartStopOnce can be embedded in a struct to help implement types.Service.\n\n```go\nfunc (s *StartStopOnce) Healthy() error\n```\nHealthy returns ErrNotStarted if the state is not started. Override this per-service with more specific implementations.\n\n```go\nfunc (s *StartStopOnce) IfNotStopped(f func()) (ok bool)\n```\nIfNotStopped runs the func and returns true if in any state other than Stopped\n\n```go\nfunc (s *StartStopOnce) IfStarted(f func()) (ok bool)\n```\nIfStarted runs the func and returns true only if started, otherwise returns false\n\n```go\nfunc (s *StartStopOnce) Ready() error\n```\nReady returns ErrNotStarted if the state is not started.\n\n```go\nfunc (s *StartStopOnce) StartOnce(name string, fn func() error) error\n```\nStartOnce sets the state to Started\n\n```go\nfunc (s *StartStopOnce) State() startStopOnceState\n```\nState retrieves the current state\n\n```go\nfunc (s *StartStopOnce) StopOnce(name string, fn func() error) error\n```\nStopOnce sets the state to Stopped\n\n```go\ntype Subprocesses struct {\n\t// contains filtered or unexported fields\n}\n```\nSubprocesses is an abstraction over the following pattern of sync.WaitGroup:\n\nvar wg sync.Subprocesses wg.Add(1) go func() { defer wg.Done() ... }()\n\nWhich becomes:\n\nvar subs utils.Subprocesses subs.Go(func() { ... })\n\nNote that it's important to not call Subprocesses.Wait() when there are no \\`Go()\\`ed functions in progress. This will panic. There are two cases when this can happen: 1. all the \\`Go()\\`ed functions started before the call to \\`Wait()\\` have already returned, maybe because a system-wide error or an already cancelled context. 2. Wait() gets called before any function is executed with \\`Go()\\`.\n\nReusing a Subprocesses instance is discouraged. See mode details here [https://pkg.go.dev/sync#WaitGroup.Add](https://pkg.go.dev/sync#WaitGroup.Add))\n\n```go\nfunc (s *Subprocesses) Go(f func())\n```\nGo calls the given function in a new goroutine.\n\n```go\nfunc (s *Subprocesses) Wait()\n```\nWait blocks until all function calls from the Go method have returned.\n\n```go\ntype URL url.URL\n```\nURL extends url.URL to implement encoding.TextMarshaler.\n\n```go\nfunc MustParseURL(s string) *URL\n```\n\n```go\nfunc ParseURL(s string) (*URL, error)\n```\n\n```go\nfunc (u *URL) MarshalText() ([]byte, error)\n```\n\n```go\nfunc (u *URL) UnmarshalText(input []byte) error\n```\n\n","path":"github.com/GoPlugin/pluginV2Lib/pluginV2-relay/pkg/utils","name":"utils","synopsis":"","isRedistributable":true}
