当前位置: 首页>>代码示例>>Golang>>正文


Golang WorkPool.Submit方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/gunk/workpool.WorkPool.Submit方法的典型用法代码示例。如果您正苦于以下问题:Golang WorkPool.Submit方法的具体用法?Golang WorkPool.Submit怎么用?Golang WorkPool.Submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/gunk/workpool.WorkPool的用法示例。


在下文中一共展示了WorkPool.Submit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fetchStateAndBuildZones

func fetchStateAndBuildZones(logger lager.Logger, workPool *workpool.WorkPool, clients map[string]rep.Client, metricEmitter auctiontypes.AuctionMetricEmitterDelegate) map[string]Zone {
	wg := &sync.WaitGroup{}
	zones := map[string]Zone{}
	lock := &sync.Mutex{}

	wg.Add(len(clients))
	for guid, client := range clients {
		guid, client := guid, client
		workPool.Submit(func() {
			defer wg.Done()
			state, err := client.State()
			if err != nil {
				metricEmitter.FailedCellStateRequest()
				logger.Error("failed-to-get-state", err, lager.Data{"cell-guid": guid})
				return
			}

			if state.Evacuating {
				return
			}

			cell := NewCell(logger, guid, client, state)
			lock.Lock()
			zones[state.Zone] = append(zones[state.Zone], cell)
			lock.Unlock()
		})
	}

	wg.Wait()

	return zones
}
开发者ID:layer-x,项目名称:pluggable-auction,代码行数:32,代码来源:zone_builder.go

示例2:

	default:
		panic(fmt.Sprintf("unknown communication mode: %s", communicationMode))
	}
})

var _ = BeforeEach(func() {
	var err error
	workPool, err = workpool.NewWorkPool(workers)
	Expect(err).NotTo(HaveOccurred())

	wg := &sync.WaitGroup{}
	wg.Add(len(cells))
	for _, cell := range cells {
		cell := cell
		workPool.Submit(func() {
			cell.Reset()
			wg.Done()
		})
	}
	wg.Wait()

	util.ResetGuids()

	runnerDelegate = NewAuctionRunnerDelegate(cells)
	metricEmitterDelegate := NewAuctionMetricEmitterDelegate()
	runner = auctionrunner.New(
		runnerDelegate,
		metricEmitterDelegate,
		clock.NewClock(),
		workPool,
		logger,
	)
开发者ID:emc-xchallenge,项目名称:auction,代码行数:32,代码来源:simulation_suite_test.go

示例3:

					unblockChan := unblockChan
					calledChan <- i
					<-unblockChan
				}
			}

			var err error
			pool, err = workpool.NewWorkPool(maxWorkers)
			Expect(err).NotTo(HaveOccurred())
		})

		Describe("Submit", func() {
			Context("when submitting less work than the max number of workers", func() {
				It("should run the passed-in work", func() {
					for i := 0; i < maxWorkers-1; i++ {
						pool.Submit(work(i))
					}

					for i := 0; i < maxWorkers-1; i++ {
						Eventually(calledChan).Should(Receive(Equal(i)))
					}
				})
			})

			Context("when submitting work equal to the number of workers", func() {
				It("should run the passed-in work concurrently", func() {
					for i := 0; i < maxWorkers; i++ {
						pool.Submit(work(i))
					}

					for i := 0; i < maxWorkers; i++ {
开发者ID:hpcloud,项目名称:statsd-injector,代码行数:31,代码来源:workpool_test.go


注:本文中的github.com/cloudfoundry/gunk/workpool.WorkPool.Submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。