core

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 2 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Buffer

func Buffer[A any](in <-chan A, size int) <-chan A

func Drain

func Drain[A any](in <-chan A)

func FilterMap added in v0.3.0

func FilterMap[A, B any](in <-chan A, n int, f func(A) (B, bool)) <-chan B

func Loop

func Loop[A, B any](in <-chan A, done chan<- B, n int, f func(A))

Loop processes items from the input channel concurrently using n goroutines. If the done channel is not nil, it will be closed after all items are processed.

func Merge

func Merge[A any](ins ...<-chan A) <-chan A

func OrderedFilterMap added in v0.3.0

func OrderedFilterMap[A, B any](in <-chan A, n int, f func(A) (B, bool)) <-chan B

func OrderedLoop

func OrderedLoop[A, B any](in <-chan A, done chan<- B, n int, f func(a A, canWrite <-chan struct{}))

OrderedLoop is similar to Loop, but it allows the caller to write results to a channel in the same order as the items were read from the input. If the done channel is not nil, it will be closed after all items are processed. A special "canWrite" channel is passed to the user's function f. A typical implementation of f performs the following steps:

  • Do some processing (this part is executed concurrently).
  • Read from the canWrite channel exactly once. This step is required. Otherwise, behavior is undefined.
  • Write the result of the processing somewhere. This step is optional.

This way, processing is done concurrently, but results are written in order.

func SendNB added in v0.9.0

func SendNB[A any](out chan<- A, x A) bool

Types

type DurableMutex added in v0.9.0

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

DurableMutex is a mutual exclusion lock whose contending callers block durably when used inside a testing/synctest bubble.

Most critical sections do plain non-blocking work. For them, a stock sync.Mutex is the right choice, with or without synctest. DurableMutex exists for one specific pattern: critical sections that do durably blocking operations while holding the lock - for example, atomically receiving values from a channel and appending them to a slice.

Under synctest, the stock mutex breaks this pattern: while the holder is durably blocked on a channel, other goroutines are non-durably blocked on the Lock() calls, so the bubble can neither advance time nor report a deadlock, and the test freezes. With DurableMutex, the test runs normally, and a genuine deadlock is caught and reported by the framework.

DurableMutex does not attempt to prevent starvation. Under contention, acquisition order depends on runtime scheduling, and the same goroutine can win the lock 1000 times in a row. Use it only when waiters are interchangeable and it does not matter which one wins the lock.

A DurableMutex used within a synctest bubble is local to that bubble: every Lock and Unlock call on it must occur in the same bubble.

The zero value is ready to use. Unlocking an unlocked mutex panics, and a DurableMutex must not be copied after first use.

func (*DurableMutex) Lock added in v0.9.0

func (m *DurableMutex) Lock()

func (*DurableMutex) Unlock added in v0.9.0

func (m *DurableMutex) Unlock()

type Pool added in v0.9.0

type Pool[T any] struct {
	// New creates a value when the pool is empty. It is required.
	New func() T

	// Reset prepares a value for reuse. It may be nil.
	Reset func(T)

	// Unsynchronized disables the pool's own locking, leaving the caller
	// responsible for serializing Get and Put. It is for callers that already
	// hold a lock covering both.
	Unsynchronized bool
	// contains filtered or unexported fields
}

Pool is a pool of reusable values. It grows on demand and never shrinks; it's the caller's responsibility to ensure that the pool stays bounded.

A Pool is safe for concurrent use unless Unsynchronized is set. Its fields must not be changed once the pool is in use.

func (*Pool[T]) Get added in v0.9.0

func (p *Pool[T]) Get() T

Get returns a value from the pool or a new one if the pool is empty.

func (*Pool[T]) Put added in v0.9.0

func (p *Pool[T]) Put(item T)

Put returns a value to the pool, transferring its ownership: the value must not be used afterward.

Jump to

Keyboard shortcuts

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