diff options
author | 2024-09-16 11:06:00 +0200 | |
---|---|---|
committer | 2024-09-16 09:06:00 +0000 | |
commit | b2572b9e074ebbce8bcf1b9979d4d8ea066650d6 (patch) | |
tree | 0c2a08ed63b582676ce7661252a6917db751c62a /vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go | |
parent | [chore]: Bump golang.org/x/net from 0.28.0 to 0.29.0 (#3303) (diff) | |
download | gotosocial-b2572b9e074ebbce8bcf1b9979d4d8ea066650d6.tar.xz |
[chore] Bump otel deps -> v1.30.0/v0.52.0 (#3307)
Diffstat (limited to 'vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go')
-rw-r--r-- | vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go b/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go index f7f40a16a..19b9d6392 100644 --- a/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go +++ b/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go @@ -53,16 +53,28 @@ func NewCallbackSerializer(ctx context.Context) *CallbackSerializer { return cs } -// Schedule adds a callback to be scheduled after existing callbacks are run. +// TrySchedule tries to schedules 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 (cs *CallbackSerializer) TrySchedule(f func(ctx context.Context)) { + cs.callbacks.Put(f) +} + +// 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. // -// 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. -func (cs *CallbackSerializer) Schedule(f func(ctx context.Context)) bool { - return cs.callbacks.Put(f) == nil +// Callbacks are expected to honor the context when performing any blocking +// operations, and should return early when the context is canceled. +func (cs *CallbackSerializer) ScheduleOr(f func(ctx context.Context), onFailure func()) { + if cs.callbacks.Put(f) != nil { + onFailure() + } } func (cs *CallbackSerializer) run(ctx context.Context) { |