concurrency.go 436 B

12345678910111213141516171819202122232425
  1. package task
  2. func (e *Executor) acquireConcurrencyLimit() func() {
  3. if e.concurrencySemaphore == nil {
  4. return emptyFunc
  5. }
  6. e.concurrencySemaphore <- struct{}{}
  7. return func() {
  8. <-e.concurrencySemaphore
  9. }
  10. }
  11. func (e *Executor) releaseConcurrencyLimit() func() {
  12. if e.concurrencySemaphore == nil {
  13. return emptyFunc
  14. }
  15. <-e.concurrencySemaphore
  16. return func() {
  17. e.concurrencySemaphore <- struct{}{}
  18. }
  19. }
  20. func emptyFunc() {}