limiter

package
v0.0.0-...-fd2add7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2016 License: Apache-2.0, Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package limiter schedules job execution while maintaining an upper limit on concurrency

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 schedules go routines for execution, while ensuring that no more than a pre-set limit run at any time.

func New

func New(m int) *Limiter

New creates a new limiter with limit m.

func (*Limiter) Close

func (l *Limiter) Close()

Close closes a session.

func (*Limiter) Go

func (l *Limiter) Go(f func())

Go executes the function f when the goroutine limit allows it. Go wraps the execution of f around an Open/Close pair.

func (*Limiter) Init

func (l *Limiter) Init(m int) *Limiter

Init resets this limiter and sets its limit to m.

func (*Limiter) Open

func (l *Limiter) Open()

Open blocks until there are fewer than limit unclosed sessions. A session begins when Open returns.

func (*Limiter) Throttle

func (l *Limiter) Throttle(f func())

Throttle executes copies of f greedily and continuously, making sure that at no time the limit is exceeded.

func (*Limiter) Wait

func (l *Limiter) Wait()

Wait blocks until all unclosed invokations to Open have been closed.

Jump to

Keyboard shortcuts

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