entered

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package entered is the shared mechanism that keeps upstream's start and resume order across goroutines.

Upstream code runs on one JavaScript event loop. A function it starts runs synchronously up to its first await before the next one starts, and continuations of promises settled together run in settlement order, each up to its next await. A Go port that starts or wakes several goroutines at once loses that order: the runtime runs them in no fixed order and, through its runnext slot, often runs the most recently readied first. This package lets a caller wait until a goroutine it started or woke has "entered": it is parked in a wait, or it has exited, so the next one can be started or woken in upstream's order.

A goroutine's state is read from a goroutine dump, polled after a short grace period with exponential backoff. A sync.Mutex, sync.RWMutex or semaphore wait is not a wait here, except for AwaitBlocked: upstream code cannot block on a lock, so a lock in Go code is part of its synchronous work, unless the caller may hold the lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await(id uint64, done <-chan struct{})

Await blocks until goroutine id is parked in a wait or has exited, or done (which may be nil) is closed. Called right after a send or close that readied id, it returns once id has run up to its next wait.

func AwaitBlocked

func AwaitBlocked(ctx context.Context, id uint64, done <-chan struct{}) error

AwaitBlocked is Await for a caller that may itself hold a lock the goroutine needs, and that stops waiting when ctx is done. Besides a goroutine parked in a wait, one waiting for a sync.Mutex, sync.RWMutex or semaphore has entered: it has run up to a wait, and the caller, which cannot tell whose lock it is, must not wait for it. It returns the cause of ctx when ctx ended the wait, and nil otherwise.

func AwaitUnless

func AwaitUnless(id uint64, done <-chan struct{}, busy func() bool)

AwaitUnless is Await, except that a wait id is in while busy reports true is not counted: busy marks a wait that is not the goroutine's own (for example a hand-off of its work to another goroutine that runs it). busy may be nil.

func Go

func Go(fn func()) (wait func())

Go runs fn on a new goroutine and returns wait, which blocks until fn has entered: it returned, or its goroutine is parked in a wait. wait may be called at most once; a caller that never calls it pays no polling.

func Parked

func Parked(id uint64, stacks []byte) (parked, found bool, buffer []byte)

Parked reports whether goroutine id is parked in a wait and whether it exists, reusing (and returning) stacks as its buffer. It is not parked while running, runnable, in a system call (a synchronous system call is work, as upstream's synchronous I/O) or waiting for a sync.Mutex, sync.RWMutex or semaphore.

Types

This section is empty.

Jump to

Keyboard shortcuts

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