Exemple #1
0
func ExampleWorker_START_WITHOUT_ACCU() {
	FullStream(str, 10)
	output.Clean()

	wg := new(sync.WaitGroup)

	fn := func(item string, Accu map[string]interface{}) {
		Accu[item] = "checked"
	}

	worker, err := stream.NewWorker(config)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	worker.Action = fn
	worker.Output = output
	worker.Accumulate = false

	go WrapWorker(worker, wg)

	str.Notify("WAKEUP")
	str.Notify("KILL")

	wg.Wait()

	fmt.Printf("OUTPUT STREAM: %d\n", output.Size())

	// Output:
	//
	// OUTPUT STREAM: 10
}
Exemple #2
0
func ExampleStream_Notify() {
	str, err := stream.New("test_stream", config)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	wg := new(sync.WaitGroup)

	w1, err := stream.NewWorker(config)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	w2, err := stream.NewWorker(config)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	go WrapWorker(w1, wg)
	go WrapWorker(w2, wg)

	res, err := str.Notify("KILL")
	if err != nil {
		fmt.Printf("ERROR %s\n", err)
		return
	}

	fmt.Printf("CONNECTED WORKERS: %d\n", res)
	wg.Wait()

	// Output:
	// CONNECTED WORKERS: 2
}