kernel

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 7 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitChan added in v0.23.0

func EmitChan[T any](k *EmitterIO, codec Encoder[T]) (chan<- T, <-chan T)

Creates pair of channels within kernel to emit messages to broker.

func EmitEvent added in v0.24.0

func EmitEvent[E swarm.Event[M, T], M, T any](k *EmitterIO, codec Encoder[swarm.Event[M, T]]) (chan<- swarm.Event[M, T], <-chan swarm.Event[M, T])

Creates pair of channels within kernel to events to broker.

func RecvChan added in v0.23.0

func RecvChan[T any](k *ListenerIO, codec Decoder[T]) (<-chan swarm.Msg[T], chan<- swarm.Msg[T])

RecvChan creates pair of channels within kernel to receive messages

func RecvEvent added in v0.24.0

func RecvEvent[E swarm.Event[M, T], M, T any](k *ListenerIO, codec Decoder[swarm.Event[M, T]]) (<-chan swarm.Event[M, T], chan<- swarm.Event[M, T])

RecvEvent creates pair of channels within kernel to receive events

Types

type Bridge added in v0.20.0

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

Bridge Lambda's main function to Listener interface Bridge is single threaded and should be used in the context of Lambda handler only.

Bridge implements Ask interface for the Lambda handler to receive messages. Dispatch and Ask & Ack are corner stones for this adapter. Dispatch blocks until all messages are Asked and Acked by the kernel.

func NewBridge added in v0.20.0

func NewBridge(cfg swarm.Config) *Bridge

func (*Bridge) Ack added in v0.20.0

func (s *Bridge) Ack(ctx context.Context, digest swarm.Digest) error

Acknowledge processed message, allowing lambda handler progress

func (*Bridge) Ask added in v0.20.0

func (s *Bridge) Ask(ctx context.Context) ([]swarm.Bag, error)

Ask converts input of Lambda handler to the context of the kernel

func (*Bridge) Close added in v0.23.1

func (s *Bridge) Close() error

func (*Bridge) Dispatch added in v0.20.0

func (s *Bridge) Dispatch(ctx context.Context, seq []swarm.Bag) error

Dispatch the batch of messages in the context of Lambda handler.

lambda.Start(
	func(evt events.CloudWatchEvent) error {
		...
		bridge.Dispatch(bag)
	}
)

func (*Bridge) Err added in v0.20.0

func (s *Bridge) Err(ctx context.Context, digest swarm.Digest, err error) error

Acknowledge error, allowing lambda handler progress

type Decoder added in v0.20.0

type Decoder[T any] interface {
	Category() string
	Decode(swarm.Bag) (T, error)
}

Decode message from wire format

type Emitter

type Emitter interface {
	Enq(context.Context, swarm.Bag) error
	Close() error
}

Emitter defines on-the-wire protocol for swarm.Bag, covering egress use-cases

type EmitterIO added in v0.24.0

type EmitterIO struct {
	sync.WaitGroup

	// Kernel configuration
	Config swarm.Config

	// Emitter is the writer port on message broker
	Emitter Emitter
	// contains filtered or unexported fields
}

The egress part of the kernel is used to enqueue messages into message broker.

func NewEmitter added in v0.23.0

func NewEmitter(emitter Emitter, config swarm.Config) *EmitterIO

Creates a new emitter kernel with the given emitter and configuration.

func (*EmitterIO) Await added in v0.24.0

func (k *EmitterIO) Await()

Await enqueue

func (*EmitterIO) Close added in v0.24.0

func (k *EmitterIO) Close()

Close emitter

type Encoder added in v0.20.0

type Encoder[T any] interface {
	Category() string
	Encode(T) (swarm.Bag, error)
}

Encodes message into wire format

type Kernel

type Kernel struct {
	Emitter  *EmitterIO
	Listener *ListenerIO
}

func New

func New(emitter *EmitterIO, listener *ListenerIO) *Kernel

func (*Kernel) Await

func (k *Kernel) Await()

func (*Kernel) Close

func (k *Kernel) Close()

type Listener added in v0.23.0

type Listener interface {
	Ack(ctx context.Context, digest swarm.Digest) error
	Err(ctx context.Context, digest swarm.Digest, err error) error
	Ask(ctx context.Context) ([]swarm.Bag, error)
	Close() error
}

Listener defines on-the-wire protocol for swarm.Bag, covering the ingress use-cases.

type ListenerIO added in v0.24.0

type ListenerIO struct {
	sync.WaitGroup
	sync.RWMutex

	// Kernel configuration
	Config swarm.Config

	// Listener is the reader port on message broker
	Listener Listener
	// contains filtered or unexported fields
}

The ingress part of the kernel is used to dequeue messages from message broker.

func NewListener added in v0.23.0

func NewListener(listener Listener, config swarm.Config) *ListenerIO

func (*ListenerIO) Await added in v0.24.0

func (k *ListenerIO) Await()

Await reader to complete

func (*ListenerIO) Close added in v0.24.0

func (k *ListenerIO) Close()

Closes broker reader, gracefully shutdowns all I/O

type Router added in v0.20.0

type Router = interface {
	Route(context.Context, swarm.Bag) error
}

Routes messages from the ingress to the destination channel.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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