Skip to content
프로젝트

소개

go lang concurrency limiter.

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

go lang goroutine concurrency limiter

builds

Build Status

Example

limit the number of concurrent go routines to 10:

  import "github.com/korovkin/limiter"

  ...

  limit := limiter.NewConcurrencyLimiter(10)
  defer limit.WaitAndClose()

  for i := 0; i < 1000; i++ {
    limit.Execute(func() {
      // do some work
    })
  }

Real World Example:

  import "github.com/korovkin/limiter"

  ...

  limiter := limiter.NewConcurrencyLimiter(10)

  httpGoogle := int(0)
  limiter.Execute(func() {
    resp, err := http.Get("https://www.google.com/")
    Expect(err).To(BeNil())
    defer resp.Body.Close()
    httpGoogle = resp.StatusCode
  })

  httpApple := int(0)
  limiter.Execute(func() {
    resp, err := http.Get("https://www.apple.com/")
    Expect(err).To(BeNil())
    defer resp.Body.Close()
    httpApple = resp.StatusCode
  })

  limiter.WaitAndClose()

  log.Println("httpGoogle:", httpGoogle)
  log.Println("httpApple:", httpApple)

Concurrent IO with Error tracking:

  import "github.com/korovkin/limiter"
  ...
	a := errors.New("error a")
	b := errors.New("error b")

	concurrently := limiter.NewConcurrencyLimiterForIO(limiter.DefaultConcurrencyLimitIO)
	concurrently.Execute(func() {
		// Do some really slow IO ...
		// keep the error:
		concurrently.FirstErrorStore(a)
	})
	concurrently.Execute(func() {
		// Do some really slow IO ...
		// keep the error:
		concurrently.FirstErrorStore(b)
	})
	concurrently.WaitAndClose()

	firstErr := concurrently.FirstErrorGet()
	Expect(firstErr == a || firstErr == b).To(BeTrue())

관련 프로젝트 살펴보기

불러오는 중…