future

package
v0.0.0-...-71fdcac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2023 License: BSD-3-Clause Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllFuture

type AllFuture[T proto.Message, U ErrorType] struct {
	// contains filtered or unexported fields
}

AllFuture is the underlying Future type for a call to the All() function. As with Base and Method, this future queues all the calls to Success() and Failure().

func All

func All[T proto.Message, U ErrorType](dep ...*Method[T, U]) *AllFuture[T, U]

All waits for all its dependent futures to complete and if they all complete successfully, it calls the Success function, otherwise the index of a failing future is sent to the Failure() method.

func NewAllFuture

func NewAllFuture[T proto.Message, U ErrorType](dep []*Method[T, U]) *AllFuture[T, U]

func (*AllFuture[T, U]) AllDependent

func (a *AllFuture[T, U]) AllDependent() []*Method[T, U]

func (*AllFuture[T, U]) Failure

func (a *AllFuture[T, U]) Failure(fn func(int))

func (*AllFuture[T, U]) Success

func (a *AllFuture[T, U]) Success(fn func())

type Base

type Base[T any] struct {
	// contains filtered or unexported fields
}

Base[T] represents a future computation resulting in a T. This is useful for simple value types such bool and int64. It only has one user-visible method which is Handle() and that is used to set a handler for when the value of type T actually arrives.

func NewBase

func NewBase[T any]() *Base[T]

NewBase returns a new pointer at a Base[T]. The value will be the zero value of T and the future is not marked completed. If you wish to make the zero value the result of the future you should use NewBaseWithValue or Set().

func NewBaseWithValue

func NewBaseWithValue[T any](t T) *Base[T]

NewBaseWithValue creates a new pointer a Base[T] with the given value and with future marked as completed.

func (*Base[T]) Cancel

func (f *Base[T]) Cancel()

Cancel causes the future's state to be cleared and the future to be marked completed. Any calls to Set() that occur after Cancel() and before any other calls to Handle() will have no effect. Any existing chain of Handle() functions will be removed from the future by Cancel(). Since the call to Cancel() marks the

func (*Base[T]) Completed

func (f *Base[T]) Completed() bool

Completed returns true if all the Handle() functions on this future have run. Note that is can be changed by the addition of new Handle() functions via Handle().

func (*Base[T]) Handle

func (f *Base[T]) Handle(fn func(T))

func (*Base[T]) HandleLater

func (f *Base[T]) HandleLater(fn func(T))

HnadleLater is used in the rare instance can where you have a future that has possibly completed all of its Handle() functions and you wish to delay the excution of fn until the next Set() call. Note that the default behavior of Handle() would be to run fn immediately, and thus you only need this function if you call must Set multiple times on the same future with the possibility that is already completed.

func (*Base[T]) Set

func (f *Base[T]) Set(t T) bool

Set causes the future it is called on be marked as completed with the given value. This will cause all registered Handle() functions to run. Set can be called multiple times and the effect is that only the as yet incomplete Handle() functions will be executed as a result. These previously unexecuted handle functions will be marked and and have their result values set to the value of *this* call to set. It is thus possible that different handlers will run with different values as their parameters. Set returns true if any Handle functions were run.

func (*Base[T]) String

func (f *Base[T]) String() string

Strings returns a human-friendly representation of this Base futuer. It returns if the future is complete or not.

type Completer

type Completer interface {
	CompleteMethod(ctx context.Context, msg proto.Message, resultErr int32, orig id.HostId) syscall.KernelErr
	Success(func(proto.Message))
	Failure(func(int32))
	Completed() bool
	Cancel()
}

Completer is the interface that means that a given type can be "completed" at a later time. This is used only for Methods.

type ErrorType

type ErrorType interface {
	~int32
}

type Invoker

type Invoker interface {
	// Invoke has to do the work to unmarshal the msg because it knows
	// the specific type to use whereas the caller does not.
	Invoke(ctx context.Context, msg *anypb.Any) Completer
}

Invoker is the interface that means that a given type be run as an implementation of a function..

type Method

type Method[T proto.Message, U ErrorType] struct {
	// contains filtered or unexported fields
}

Method is a special type of future that is used frequently in parigot because all the methods of a service, and the methods of clients that use that same service, must return this type. It has the special behavior that when CompleteMethod is called on this Method, the error value is compared to zero and this determines if the Success (error value is 0) or Failure (error is not 0) handler function is called.

It is thus impossible to have a Method that can behave in a failed way (call to Failure) based on the return value being 0. In this case, use a Base[int32], as parigot does.

func NewMethod

func NewMethod[T proto.Message, U ErrorType](resolve func(T), reject func(U)) *Method[T, U]

NewMethod return as method future with two types given. The T type (first) must be a proto.Message and typically is a Response object from a previous call to the Method. The error value, U, is typically a named enum that is used for error signaling by the method called.

func (*Method[T, U]) Cancel

func (m *Method[T, U]) Cancel()

Cancel causes a future to be marked completed and also to remove any and all possible calls to a Sucess() or Failure() function later. This enforces that a Cancel() is permanent, even if the future is "completed" later. Calling Cancel() on an already completed future will be ignored.

func (*Method[T, U]) CompleteMethod

func (f *Method[T, U]) CompleteMethod(ctx context.Context, result T, resultErr U)

CompleteMethod is called to indicate that the outcome, or value, of the future is now known. This method is typically called by the infrastructure of Parigot, but it can be useful to call this method directly in tests. Calling this method on completed Method future will be ignored.

func (*Method[T, U]) Completed

func (f *Method[T, U]) Completed() bool

Completed returns true if this method has already completed.

func (*Method[T, U]) Failure

func (f *Method[T, U]) Failure(fn func(U))

Failure provides a function to be called if the Method completion supplies a non zero error value. Calling failure on a completed Method that had an error causes the given function to run immediately.

func (*Method[T, U]) String

func (f *Method[T, U]) String() string

String() returns a human-friendly version of this Method future. It shows it is resolved and if so, if the completion was an error.

func (*Method[T, U]) Success

func (f *Method[T, U]) Success(fn func(T))

Success provides a function to be called if the Method returns a success. Calling Success() on an already completed method causes the code supplied in the success method to be run immediately if the future was resolved successfully.

func (*Method[T, U]) ValueErr

func (f *Method[T, U]) ValueErr() U

ValueErr may not do what you expect: This function does not force the world to stop and wait for the Error in question to be received. It can only be trusted when the function Completed() returns true and the function WasSuccess() returns false. It returns the value of the error on a completed Method.

func (*Method[T, U]) ValueResponse

func (f *Method[T, U]) ValueResponse() T

ValueResponse may not do what you expect: This function does not force the world to stop and wait for the Response in question to be received. It can only be trusted when the function Completed() returns true and the function WasSuccess() returns true. This function returns the value of a response (type T) on a completed method

func (*Method[T, U]) WaitingId

func (m *Method[T, U]) WaitingId() string

WaitingId is useful only to the go client side library. The WaitingId is a repurposing of the CallId to create a key value, a string, for use in a map, since Method[T,U] is not a valid key type in go.

func (*Method[T, U]) WasSuccess

func (f *Method[T, U]) WasSuccess() bool

WasSuccess returns true if the Method is completed and finished as a sucess. Before a Method is completed, it returns false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL