streamjoin

package
v6.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package streamjoin gives response bodies whose bytes are produced incrementally to a reader that cannot report completion while the producer that writes them is still running.

A Lambda invocation ends when the handler has returned its response and the adapter has stopped consuming the response body. A producer goroutine that is still running at that point outlives the invocation that started it: it keeps holding the execution environment, and it can resume half-finished work on a later invocation of the same environment. Every incremental body therefore hands its producer to this package, which joins the producer on both exit paths of the body reader:

  • the reader reaches EOF only after the producer has returned, so an adapter that drains a body to completion cannot return early;
  • closing the reader unblocks the producer (by closing the pipe and then canceling the producer context) and then waits for it to return, so an adapter that abandons a body also leaves no producer behind.

A producer that blocks on something this package cannot unblock — a read from a source that is neither closed nor canceled by the caller — keeps the documented io.Closer contract instead: Close unblocks blocked reads and writes. Producers must observe their context for the close path to be prompt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

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

Body is a response body backed by a producer goroutine. It implements io.ReadCloser and joins the producer on EOF and on Close.

func New

func New(parent context.Context, produce Producer) *Body

New starts produce on its own goroutine and returns the body that streams its output.

The context handed to produce is canceled when the body is closed or when parent is done, so a producer that blocks on a channel receive can also be unblocked by Close.

func (*Body) Close

func (b *Body) Close() error

Close stops the producer and waits for it to return. It is safe to call concurrently with Read, and it is idempotent.

The reader pipe is closed before the producer context is canceled. The pipe keeps the error of whichever side closed first, so a read that is blocked in the pipe — or that starts after Close — reports io.ErrClosedPipe rather than whichever of the two unblocking paths happened to win the race.

func (*Body) Read

func (b *Body) Read(p []byte) (int, error)

Read returns the producer's bytes. It reports EOF (or the producer's error) only once the producer goroutine has returned.

type Producer

type Producer func(ctx context.Context, w *io.PipeWriter)

Producer writes a response body to w. It must return when ctx is done or when writing to w fails, and it must close w before returning.

Jump to

Keyboard shortcuts

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