package grpcsync
Import Path
google.golang.org/grpc/internal/grpcsync (on go.dev)
Dependency Relation
imports 4 packages, and imported by 2 packages
Involved Source Files
callback_serializer.go
Package grpcsync implements additional synchronization primitives built upon
the sync package.
pubsub.go
Package-Level Type Names (total 4)
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.
Done returns a channel that is closed after the context passed to
NewCallbackSerializer is canceled and all callbacks have been executed.
ScheduleOr schedules the provided callback function f to be executed in the
order it was added. If the context passed to NewCallbackSerializer has been
canceled before this method is called, the onFailure callback will be
executed inline instead.
Callbacks are expected to honor the context when performing any blocking
operations, and should return early when the context is canceled.
TrySchedule tries to schedule the provided callback function f to be
executed in the order it was added. This is a best-effort operation. If the
context passed to NewCallbackSerializer was canceled before this method is
called, the callback will not be scheduled.
Callbacks are expected to honor the context when performing any blocking
operations, and should return early when the context is canceled.
func NewCallbackSerializer(ctx context.Context) *CallbackSerializer
Event represents a one-time event that may occur in the future.
Done returns a channel that will be closed when Fire is called.
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. If Fire returns false, it is possible
the Done channel has not been closed yet.
HasFired returns true if Fire has been called.
func NewEvent() *Event
PubSub is a simple one-to-many publish-subscribe system that supports
messages of arbitrary type. It guarantees that messages are delivered in
the same order in which they were published.
Publisher invokes the Publish() method to publish new messages, while
subscribers interested in receiving these messages register a callback
via the Subscribe() method.
Once a PubSub is stopped, no more messages can be published, but any pending
published messages will be delivered to the subscribers. Done may be used
to determine when all published messages have been delivered.
Done returns a channel that is closed after the context passed to NewPubSub
is canceled and all updates have been sent to subscribers.
Publish publishes the provided message to the PubSub, and invokes
callbacks registered by subscribers asynchronously.
Subscribe registers the provided Subscriber to the PubSub.
If the PubSub contains a previously published message, the Subscriber's
OnMessage() callback will be invoked asynchronously with the existing
message to begin with, and subsequently for every newly published message.
The caller is responsible for invoking the returned cancel function to
unsubscribe itself from the PubSub.
func NewPubSub(ctx context.Context) *PubSub
Subscriber represents an entity that is subscribed to messages published on
a PubSub. It wraps the callback to be invoked by the PubSub when a new
message is published.
OnMessage is invoked when a new message is published. Implementations
must not block in this method.
func (*PubSub).Subscribe(sub Subscriber) (cancel func())
Package-Level Functions (total 3)
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.
NewEvent returns a new, ready-to-use Event.
NewPubSub returns a new PubSub instance. Users should cancel the
provided context to shutdown the PubSub.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |