toolsched

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 4 Imported by: 0 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

Overview

Package toolsched holds the daemon-wide scheduling primitives of native runs: a semaphore for model requests and keyed locks and batches for tool calls.

Index

Constants

This section is empty.

Variables

View Source
var ErrPanicked = errors.New("tool call panicked")

ErrPanicked reports a call that panicked; the batch goes on.

Functions

This section is empty.

Types

type Batch

type Batch[T any] struct {
	// contains filtered or unexported fields
}

Batch runs the calls of one model reply concurrently: calls sharing a key run one at a time in the order they were started, each holding its key in Locks, and at most limit calls run at once. Only the goroutine that created the batch may call its methods; Next reports every started call exactly once.

func NewBatch

func NewBatch[T any](ctx context.Context, locks *Locks, limit int) *Batch[T]

NewBatch returns a batch whose calls run under ctx.

func (*Batch[T]) Go

func (b *Batch[T]) Go(index int, key string, run func(context.Context) T)

Go starts call index under key; run gets the batch's context.

func (*Batch[T]) Next

func (b *Batch[T]) Next() Done[T]

Next waits until a started call finishes and reports it.

func (*Batch[T]) Running

func (b *Batch[T]) Running() int

Running is how many started calls Next has not reported yet.

type Done

type Done[T any] struct {
	Index int
	Value T
	Err   error
}

Done is a finished call: Value is what it returned, or Err says why it did not run (its context stopped) or did not return (ErrPanicked).

type Locks

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

Locks is a keyed mutex shared by every run of the daemon: holders of one key run one at a time; the empty key is never locked.

func NewLocks

func NewLocks() *Locks

NewLocks returns an empty set of keyed locks.

func (*Locks) Lock

func (l *Locks) Lock(ctx context.Context, key string) (unlock func(), err error)

Lock waits until key is free or ctx stops; unlock frees the key.

type Semaphore

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

Semaphore lets at most n holders in at once; a nil Semaphore never blocks.

func NewSemaphore

func NewSemaphore(n int) *Semaphore

NewSemaphore returns a semaphore with n slots, or nil when n <= 0.

func (*Semaphore) Acquire

func (s *Semaphore) Acquire(ctx context.Context) (release func(), err error)

Acquire waits for a free slot or until ctx stops; release gives the slot back.

func (*Semaphore) Resize added in v0.2.1

func (s *Semaphore) Resize(n int)

Resize sets the number of slots to n > 0; holders over a smaller limit keep their slots until they release them.

Jump to

Keyboard shortcuts

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