Ejemplo n.º 1
0
func ExecuteConcurrently(schedule <-chan int, tasks <-chan func(context.Context), workloadCtx context.Context) {
	var wg sync.WaitGroup
	indexCounter := 0

	for increment := range schedule {

		for i := 0; i < increment; i++ {
			wg.Add(1)
			go func(t <-chan func(context.Context), ctx context.Context) {
				defer wg.Done()
				for task := range t {
					ctx.PutInt("iterationIndex", indexCounter)
					indexCounter++
					task(ctx)
				}
			}(tasks, workloadCtx.Clone())
		}
	}
	wg.Wait()
}
Ejemplo n.º 2
0
			result, _ := localContext.GetBool("key")
			Ω(result).Should(Equal(true))
		})

		It("can store float64 value as provided", func() {
			localContext.PutFloat64("key", float64(3.14))

			result, _ := localContext.GetFloat64("key")
			Ω(result).Should(Equal(float64(3.14)))
		})
	})

	Context("Cloning map", func() {
		It("returns a copy of the cloned context map", func() {
			localContext.PutString("str1", "abc")
			localContext.PutString("str2", "def")

			cloned := localContext.Clone()

			localContext.PutString("str1", "123")

			result, _ := localContext.GetString("str1")
			Ω(result).Should(Equal("123"))

			result, _ = cloned.GetString("str1")
			Ω(result).Should(Equal("abc"))
		})
	})

})