Skip to content

singlestore-labs/simultaneous

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simultaneous - limit the number of concurrent operations, Go

GoDoc unit tests report card codecov

Install:

go get github.com/singlestore-labs/simultaneous

Simultaneous limits the number of concurrent operations. It supports passing proof of obtaining a limit.

Simple usage

var limit = simultaneous.New[any](10)

func unlimitedWait() {
	defer limit.Forever()()
	// do stuff
}

func limitedWait() error {
	done, err := limit.Timeout(time.Minute)
	if err != nil { 
		return fmt.Errorf("timeout: %w", err)
	}
	defer done()

	// do stuff
}

Proving that operating within a limit

You can prove that you've got permission

type myLimitType struct{}

var limit = simultaneous.New[myLimitType](10)

func wantsProof(_ Enforced[myLimitType]) {
	// do something
}

func providesProof() {
	done := limit.Forever()
	defer done()
	wantsProof(done)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •