plimit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package plimit provides a faithful port of the npm p-limit library: it runs an unbounded number of scheduled functions while capping the number that execute concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter runs scheduled functions with a bounded level of concurrency.

func New

func New(concurrency int) *Limiter

New creates a Limiter that allows at most concurrency functions to run at the same time. A concurrency of 1 or less serializes execution.

func (*Limiter) ActiveCount

func (l *Limiter) ActiveCount() int

ActiveCount returns the number of functions currently executing.

func (*Limiter) Go

func (l *Limiter) Go(fn func())

Go schedules fn to run. It never blocks the caller: the function is queued and starts as soon as a concurrency slot becomes available. Use Wait to block until all scheduled functions have completed.

func (*Limiter) PendingCount

func (l *Limiter) PendingCount() int

PendingCount returns the number of functions scheduled but not yet started.

func (*Limiter) Run

func (l *Limiter) Run(fn func())

Run schedules fn the same way as Go but blocks the caller until a concurrency slot is available before returning. fn itself still runs in its own goroutine, so Run returning means fn has started (or is about to start).

func (*Limiter) Wait

func (l *Limiter) Wait()

Wait blocks until all scheduled functions have finished executing.

Jump to

Keyboard shortcuts

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