synctest

package
v0.187.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Phaser

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

Phaser is a synchronization primitive for coordinating multiple goroutines. I that combines the behavior of a latch, barrier, and phaser. Goroutines may register via Wait, be released one at a time via Signal or all at once via Broadcast. Ultimately, using Finish can ensure, that all wait is released, to ensure that all waiter is released.

Like sync.Mutex, a zero value Phaser is ready to use right away. If you’re using a sync.Mutex to protect shared resources, you can pass it as an optional argument to Phaser.Wait. This lets the mutex be released while waiting and automatically reacquired upon the end of waiting.

Example
package main

import (
	"go.llib.dev/testcase/pkg/synctest"
)

func main() {
	var p synctest.Phaser
	defer p.Finish()

	go func() { p.Wait() }()
	go func() { p.Wait() }()
	go func() { p.Wait() }()

	p.Broadcast() // wait no longer blocks
}

func (*Phaser) Broadcast added in v0.186.0

func (p *Phaser) Broadcast()

func (*Phaser) Finish

func (p *Phaser) Finish()

Finish lets all waiting goroutines continue immediately. After it’s called, any new calls to Wait will also return right away.

func (*Phaser) Len added in v0.186.0

func (p *Phaser) Len() int

func (*Phaser) Signal added in v0.186.0

func (p *Phaser) Signal()

func (*Phaser) Wait

func (p *Phaser) Wait(ls ...sync.Locker)

Jump to

Keyboard shortcuts

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