cpc

package
v3.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidReplyType = errors.New("reply type does not match")

Functions

func SendTyped

func SendTyped[T any](ctx context.Context, c *CPC, value any) (T, error)

SendTyped is similar to CPC.Send, but ensure that reply is of the given Type T.

Types

type CPC

type CPC struct {
	// contains filtered or unexported fields
}

CPC Channel Procedure Call. A play on RPC, but with channels. Use this type to send requests and wait for replies from a goroutine.

func NewCPC

func NewCPC() *CPC

func (*CPC) Close

func (c *CPC) Close()

Close closes the CPC channel and no further requests should be made.

func (*CPC) Receive

func (c *CPC) Receive(ctx context.Context, f func(context.Context, *Request))

Receive invokes the function on all the request that arrive.

func (*CPC) ReceiveCh

func (c *CPC) ReceiveCh() <-chan *Request

ReceiveCh returns the channel on which all requests are sent.

func (*CPC) Send

func (c *CPC) Send(ctx context.Context, value any) (any, error)

Send sends a request which expects a reply.

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request contains the data for a request as well as the means to reply to a request.

func (*Request) Reply

func (r *Request) Reply(ctx context.Context, value any, err error)

Reply should be used to send a reply to a given request.

func (*Request) Value

func (r *Request) Value() any

Value returns the request value.

Jump to

Keyboard shortcuts

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