package grpcsync
import "google.golang.org/grpc/internal/grpcsync"
Package grpcsync implements additional synchronization primitives built upon the sync package.
Index ¶
- func OnceFunc(f func()) func()
- type CallbackSerializer
- func NewCallbackSerializer(ctx context.Context) *CallbackSerializer
- func (t *CallbackSerializer) Schedule(f func(ctx context.Context)) bool
- type Event
Functions ¶
func OnceFunc ¶
func OnceFunc(f func()) func()
OnceFunc returns a function wrapping f which ensures f is only executed once even if the returned function is executed multiple times.
Types ¶
type CallbackSerializer ¶
type CallbackSerializer struct { // Done is closed once the serializer is shut down completely, i.e all // scheduled callbacks are executed and the serializer has deallocated all // its resources. Done chan struct{} // contains filtered or unexported fields }
CallbackSerializer provides a mechanism to schedule callbacks in a synchronized manner. It provides a FIFO guarantee on the order of execution of scheduled callbacks. New callbacks can be scheduled by invoking the Schedule() method.
This type is safe for concurrent access.
func NewCallbackSerializer ¶
func NewCallbackSerializer(ctx context.Context) *CallbackSerializer
NewCallbackSerializer returns a new CallbackSerializer instance. The provided context will be passed to the scheduled callbacks. Users should cancel the provided context to shutdown the CallbackSerializer. It is guaranteed that no callbacks will be added once this context is canceled, and any pending un-run callbacks will be executed before the serializer is shut down.
func (*CallbackSerializer) Schedule ¶
func (t *CallbackSerializer) Schedule(f func(ctx context.Context)) bool
Schedule adds a callback to be scheduled after existing callbacks are run.
Callbacks are expected to honor the context when performing any blocking operations, and should return early when the context is canceled.
Return value indicates if the callback was successfully added to the list of callbacks to be executed by the serializer. It is not possible to add callbacks once the context passed to NewCallbackSerializer is cancelled.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a one-time event that may occur in the future.
func NewEvent ¶
func NewEvent() *Event
NewEvent returns a new, ready-to-use Event.
func (*Event) Done ¶
func (e *Event) Done() <-chan struct{}
Done returns a channel that will be closed when Fire is called.
func (*Event) Fire ¶
Fire causes e to complete. It is safe to call multiple times, and concurrently. It returns true iff this call to Fire caused the signaling channel returned by Done to close.
func (*Event) HasFired ¶
HasFired returns true if Fire has been called.
Source Files ¶
callback_serializer.go event.go oncefunc.go
- Version
- v1.56.1
- Published
- Jun 21, 2023
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 2 minutes ago –
Tools for package owners.