cpc

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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