github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/x/mongo/driver/operation_exhaust.go (about)

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package driver
     8  
     9  import (
    10  	"context"
    11  	"errors"
    12  )
    13  
    14  // ExecuteExhaust reads a response from the provided StreamerConnection. This will error if the connection's
    15  // CurrentlyStreaming function returns false.
    16  func (op Operation) ExecuteExhaust(ctx context.Context, conn StreamerConnection) error {
    17  	if !conn.CurrentlyStreaming() {
    18  		return errors.New("exhaust read must be done with a connection that is currently streaming")
    19  	}
    20  
    21  	res, err := op.readWireMessage(ctx, conn)
    22  	if err != nil {
    23  		return err
    24  	}
    25  	if op.ProcessResponseFn != nil {
    26  		// Server, ConnectionDescription, and CurrentIndex are unused in this mode.
    27  		info := ResponseInfo{
    28  			ServerResponse: res,
    29  			Connection:     conn,
    30  		}
    31  		if err = op.ProcessResponseFn(info); err != nil {
    32  			return err
    33  		}
    34  	}
    35  
    36  	return nil
    37  }