Help us shape the future of Go! Take the 2026 Go Developer Survey

pull

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package pull is the shared shape of the queue-like transports (Pub/Sub, SQS, Service Bus): a goroutine pulls messages and holds each one's handle, the receive keeps some of them, and when the run ends the kept handles are acknowledged and every other handle is given back to the service.

Skipped messages are held until the end rather than given back at once: an immediate give-back would deliver them to this same run again and again.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[H any](ctx context.Context, rc transport.Receive, idOf func(transport.Message) string, pump Pump[H], settle Settle[H]) ([]transport.Message, error)

Collect runs pump, collects the receive, and settles. idOf names a message the way the pump's Hold calls do. The messages kept are returned with any error, including ErrTimeout (the partial list); a settle failure is returned only when nothing else failed.

Goroutine ownership: Collect starts the pump goroutine and waits for it before it settles.

Types

type Book

type Book[H any] struct {
	// contains filtered or unexported fields
}

Book remembers the handle (an ack id, a receipt handle, a received message) of every message pulled, by message id, and which ones were kept. It is safe for the pulling goroutine and the collector to use together.

func NewBook

func NewBook[H any]() *Book[H]

NewBook returns an empty book.

func (*Book[H]) Hold

func (b *Book[H]) Hold(id string, handle H)

Hold records the handle of a message pulled. A message pulled again keeps its place and gets the newer handle.

type Pump

type Pump[H any] func(ctx context.Context, book *Book[H], in chan<- transport.Message) error

Pump pulls messages into in until ctx ends, holding each handle in book. A message it does not send on (its own, for instance) is still held, so it is given back at the end. The error is a failed pull, never the end of the run.

type Settle

type Settle[H any] func(ctx context.Context, kept, others []H) error

Settle acknowledges the kept handles and gives the others back. It gets a context of its own that outlives the run.

Jump to

Keyboard shortcuts

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