resource_server

package
v0.57.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructChildResource

func ConstructChildResource[T any](
	ctx context.Context,
	buildFn func(subCtx context.Context) (mux srpc.Invoker, result T, releaseFn func(), err error),
) (T, uint32, error)

ConstructChildResource creates a sub-resource with a managed context.

Extracts the ResourceClientContext from ctx, creates a sub-context derived from the client session (outlives the RPC call), calls buildFn with that context, and registers the resulting mux as a child resource.

On buildFn error the sub-context is canceled automatically. On success the sub-context lives until the resource is released or the client disconnects. The releaseFn returned by buildFn runs before the sub-context is canceled (user cleanup has a live context on explicit release; on client disconnect the client context is already dead which is accepted as abnormal teardown).

func NewResourceMux

func NewResourceMux(register ...func(srpc.Mux) error) srpc.Mux

NewResourceMux creates a new srpc.Mux and registers services with it. Panics if any registration function returns an error.

func WithResourceClientContext

func WithResourceClientContext(ctx context.Context, msc ResourceClientContext) context.Context

WithResourceClientContext attaches a ResourceClientContext to a Context.

Types

type RemoteResourceClient

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

RemoteResourceClient tracks one immutable ResourceClient generation.

func (*RemoteResourceClient) AddAttachedResource

func (c *RemoteResourceClient) AddAttachedResource(
	id uint32,
	label string,
	cancel context.CancelFunc,
	srpcClient srpc.Client,
	releaseFn func(),
) error

AddAttachedResource registers a client-published resource with this generation.

func (*RemoteResourceClient) AddResource

func (c *RemoteResourceClient) AddResource(mux srpc.Invoker, releaseFn func()) (uint32, error)

AddResource adds a server-created resource to this generation.

func (*RemoteResourceClient) AddResourceValue

func (c *RemoteResourceClient) AddResourceValue(mux srpc.Invoker, value any, releaseFn func()) (uint32, error)

AddResourceValue adds a server-created resource with an in-process value.

func (*RemoteResourceClient) Context

func (c *RemoteResourceClient) Context() context.Context

Context returns the generation lifecycle context.

func (*RemoteResourceClient) GetAttachedResource

func (c *RemoteResourceClient) GetAttachedResource(id uint32) (srpc.Client, error)

GetAttachedResource returns a client-published ResourceRpc client.

func (*RemoteResourceClient) GetResourceValue

func (c *RemoteResourceClient) GetResourceValue(resourceID uint32) (any, error)

GetResourceValue returns an in-process resource value.

func (*RemoteResourceClient) ReleaseResource

func (c *RemoteResourceClient) ReleaseResource(resourceID uint32) bool

ReleaseResource is server initiated and therefore notifies the client of the target as well as pending descendants.

func (*RemoteResourceClient) RemoveAttachedResource

func (c *RemoteResourceClient) RemoveAttachedResource(id uint32)

RemoveAttachedResource removes a client-published resource.

type ResourceClientContext

type ResourceClientContext interface {
	// Context returns the lifetime context of the Resource RPC request.
	Context() context.Context
	// AddResource adds a child resource with a release callback.
	AddResource(mux srpc.Invoker, releaseFn func()) (uint32, error)
	// AddResourceValue adds a child resource with an optional typed value.
	AddResourceValue(mux srpc.Invoker, value any, releaseFn func()) (uint32, error)
	// ReleaseResource releases a child resource owned by this context.
	ReleaseResource(resourceID uint32) bool
	// GetResourceValue returns the typed value for a resource.
	GetResourceValue(resourceID uint32) (any, error)
	// GetAttachedResource returns a raw attached SRPC client.
	GetAttachedResource(id uint32) (srpc.Client, error)
}

ResourceClientContext is the value attached to a Context containing information about the Resource RPC request.

func GetResourceClientContext

func GetResourceClientContext(ctx context.Context) ResourceClientContext

GetResourceClientContext returns the ResourceClientContext from the Context or nil if unset.

func MustGetResourceClientContext

func MustGetResourceClientContext(ctx context.Context) (ResourceClientContext, error)

MustGetResourceClientContext returns the ResourceClientContext from the Context or an error if unset.

type ResourceServer

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

ResourceServer serves one root resource and its client-owned descendants.

func NewResourceServer

func NewResourceServer(rootResourceMux srpc.Invoker) *ResourceServer

NewResourceServer constructs a ResourceServer for rootResourceMux.

func (*ResourceServer) Register

func (s *ResourceServer) Register(mux srpc.Mux) error

Register registers the Resource service with mux.

func (*ResourceServer) ResourceAttach

ResourceAttach allows a client to provide resources that server-side RPC handlers can invoke via getAttachedRef(id). One stream = one yamux session = N resources. Session-only Init/Ack, then Add/AddAck per resource.

func (*ResourceServer) ResourceClient

ResourceClient starts a new immutable client generation. The first packet must be Init; every later packet is one FIFO Adopt or Release control.

func (*ResourceServer) ResourceRpc

ResourceRpc routes one ResourceRpc stream to its generation-owned resource.

Jump to

Keyboard shortcuts

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