func readMultiple(
	ctx context.Context,
	bucket gcs.Bucket,
	reqs []*gcs.ReadObjectRequest) (contents [][]byte, errs []error) {
	b := syncutil.NewBundle(ctx)

	// Feed indices into a channel.
	indices := make(chan int, len(reqs))
	for i, _ := range reqs {
		indices <- i
	}
	close(indices)

	// Set up a function that deals with one request.
	contents = make([][]byte, len(reqs))
	errs = make([]error, len(reqs))

	handleRequest := func(ctx context.Context, i int) {
		var b []byte
		var err error
		defer func() {
			contents[i] = b
			errs[i] = err
		}()

		// Open a reader.
		rc, err := bucket.NewReader(ctx, reqs[i])
		if err != nil {
			err = fmt.Errorf("NewReader: %v", err)
			return
		}

		// Read from it.
		b, err = ioutil.ReadAll(rc)
		if err != nil {
			err = fmt.Errorf("ReadAll: %v", err)
			return
		}

		// Close it.
		err = rc.Close()
		if err != nil {
			err = fmt.Errorf("Close: %v", err)
			return
		}

		return
	}

	// Run several workers.
	const parallelsim = 32
	for i := 0; i < parallelsim; i++ {
		b.Add(func(ctx context.Context) (err error) {
			for i := range indices {
				handleRequest(ctx, i)
			}

			return
		})
	}

	AssertEq(nil, b.Join())
	return
}
// Issue all of the supplied read requests with some degree of parallelism.
Issue all of the supplied read requests with some degree of parallelism.
// Issue all of the supplied read requests with some degree of parallelism .
func readMultiple(
	ctx context.Context,
	bucket gcs.Bucket,
	reqs []*gcs.ReadObjectRequest) (contents [][]byte, errs []error) {
	b := syncutil.NewBundle(ctx)
	indices := make(chan int, len(reqs))
	for i, _ := range reqs {
		indices <- i
	}
	close(indices)
	contents = make([][]byte, len(reqs))
	errs = make([]error, len(reqs))
	handleRequest := func(ctx context.Context, i int) {
		var b []byte
		var err error
		defer func() {
			contents[i] = b
			errs[i] = err
		}()
		rc, err := bucket.NewReader(ctx, reqs[i])
		if err != nil {
			err = fmt.Errorf("NewReader: %v", err)
			return
		}
		b, err = ioutil.ReadAll(rc)
		if err != nil {
			err = fmt.Errorf("ReadAll: %v", err)
			return
		}
		err = rc.Close()
		if err != nil {
			err = fmt.Errorf("Close: %v", err)
			return
		}
		return
	}
	const parallelsim = 32
	for i := 0; i < parallelsim; i++ {
		b.Add(func(ctx context.Context) (err error) {
			for i := range indices {
				handleRequest(ctx, i)
			}
			return
		})
	}
	AssertEq(nil, b.Join())
	return
}
func readMultiple ( ctx context . Context , bucket gcs . Bucket , reqs [ ] * gcs . ReadObjectRequest ) ( contents [ ] [ ] byte , errs [ ] error ) { b := syncutil . NewBundle ( ctx ) indices := make ( chan int , len ( reqs ) ) for i , _ := range reqs { indices <- i } close ( indices ) contents = make ( [ ] [ ] byte , len ( reqs ) ) errs = make ( [ ] error , len ( reqs ) ) handleRequest := func ( ctx context . Context , i int ) { var b [ ] byte var err error defer func ( ) { contents [ i ] = b errs [ i ] = err } ( ) rc , err := bucket . NewReader ( ctx , reqs [ i ] ) if err != nil { err = fmt . Errorf ( " " , err ) return } b , err = ioutil . ReadAll ( rc ) if err != nil { err = fmt . Errorf ( " " , err ) return } err = rc . Close ( ) if err != nil { err = fmt . Errorf ( " " , err ) return } return } const parallelsim = 32 for i := 0 ; i < parallelsim ; i ++ { b . Add ( func ( ctx context . Context ) ( err error ) { for i := range indices { handleRequest ( ctx , i ) } return } ) } AssertEq ( nil , b . Join ( ) ) return }
Issue all of the supplied read requests with some degree of parallelism.
Issue all of the supplied read requests with some degree of parallelism .
// Feed indices into a channel. // Set up a function that deals with one request. // Open a reader. // Read from it. // Close it. // Run several workers.