func runWorkers(
	ctx context.Context,
	o *gcs.Object,
	bucket gcs.Bucket) (results []result, err error) {
	b := syncutil.NewBundle(ctx)

	// Set up a channel that is closed upon SIGINT.
	stop := make(chan struct{})
	go func() {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt)

		<-c
		log.Printf("SIGINT received. Stopping soon...")
		close(stop)
	}()

	// Start several workers making random reads.
	var wg sync.WaitGroup
	resultChan := make(chan result)
	for i := 0; i < *fWorkers; i++ {
		wg.Add(1)
		b.Add(func(ctx context.Context) (err error) {
			defer wg.Done()
			err = makeReads(ctx, o, bucket, resultChan, stop)
			if err != nil {
				err = fmt.Errorf("makeReads: %v", err)
				return
			}

			return
		})
	}

	go func() {
		wg.Wait()
		close(resultChan)
	}()

	// Accumulate results.
	b.Add(func(ctx context.Context) (err error) {
		for r := range resultChan {
			results = append(results, r)
		}

		return
	})

	err = b.Join()
	return
}
// Run workers until SIGINT is received. Return a slice of results.
Run workers until SIGINT is received. Return a slice of results.
// Run workers until SIGINT is received . Return a slice of results .
func runWorkers(
	ctx context.Context,
	o *gcs.Object,
	bucket gcs.Bucket) (results []result, err error) {
	b := syncutil.NewBundle(ctx)
	stop := make(chan struct{})
	go func() {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt)
		<-c
		log.Printf("SIGINT received. Stopping soon...")
		close(stop)
	}()
	var wg sync.WaitGroup
	resultChan := make(chan result)
	for i := 0; i < *fWorkers; i++ {
		wg.Add(1)
		b.Add(func(ctx context.Context) (err error) {
			defer wg.Done()
			err = makeReads(ctx, o, bucket, resultChan, stop)
			if err != nil {
				err = fmt.Errorf("makeReads: %v", err)
				return
			}
			return
		})
	}
	go func() {
		wg.Wait()
		close(resultChan)
	}()
	b.Add(func(ctx context.Context) (err error) {
		for r := range resultChan {
			results = append(results, r)
		}
		return
	})
	err = b.Join()
	return
}
func runWorkers ( ctx context . Context , o * gcs . Object , bucket gcs . Bucket ) ( results [ ] result , err error ) { b := syncutil . NewBundle ( ctx ) stop := make ( chan struct { } ) go func ( ) { c := make ( chan os . Signal , 1 ) signal . Notify ( c , os . Interrupt ) <- c log . Printf ( " " ) close ( stop ) } ( ) var wg sync . WaitGroup resultChan := make ( chan result ) for i := 0 ; i < * fWorkers ; i ++ { wg . Add ( 1 ) b . Add ( func ( ctx context . Context ) ( err error ) { defer wg . Done ( ) err = makeReads ( ctx , o , bucket , resultChan , stop ) if err != nil { err = fmt . Errorf ( " " , err ) return } return } ) } go func ( ) { wg . Wait ( ) close ( resultChan ) } ( ) b . Add ( func ( ctx context . Context ) ( err error ) { for r := range resultChan { results = append ( results , r ) } return } ) err = b . Join ( ) return }
Run workers until SIGINT is received.
Run workers until SIGINT is received .
// Set up a channel that is closed upon SIGINT. // Start several workers making random reads. // Accumulate results.