StartPipeline switches the connection to pipeline mode and returns a *Pipeline. In pipeline mode requests can be sent to the server without waiting for a response. Close must be called on the returned *Pipeline to return the connection to normal mode. While in pipeline mode, no methods that communic
(ctx context.Context)
| 2424 | // |
| 2425 | // Prefer ExecBatch when only sending one group of queries at once. |
| 2426 | func (pgConn *PgConn) StartPipeline(ctx context.Context) *Pipeline { |
| 2427 | if err := pgConn.lock(); err != nil { |
| 2428 | pipeline := &Pipeline{ |
| 2429 | closed: true, |
| 2430 | err: err, |
| 2431 | } |
| 2432 | pipeline.state.Init() |
| 2433 | |
| 2434 | return pipeline |
| 2435 | } |
| 2436 | |
| 2437 | pgConn.resultReader = ResultReader{closed: true} |
| 2438 | |
| 2439 | pgConn.pipeline = Pipeline{ |
| 2440 | conn: pgConn, |
| 2441 | ctx: ctx, |
| 2442 | } |
| 2443 | pgConn.pipeline.state.Init() |
| 2444 | |
| 2445 | pipeline := &pgConn.pipeline |
| 2446 | |
| 2447 | if ctx != context.Background() { |
| 2448 | select { |
| 2449 | case <-ctx.Done(): |
| 2450 | pipeline.closed = true |
| 2451 | pipeline.err = newContextAlreadyDoneError(ctx) |
| 2452 | pgConn.unlock() |
| 2453 | return pipeline |
| 2454 | default: |
| 2455 | } |
| 2456 | pgConn.contextWatcher.Watch(ctx) |
| 2457 | } |
| 2458 | |
| 2459 | return pipeline |
| 2460 | } |
| 2461 | |
| 2462 | // SendPrepare is the pipeline version of *PgConn.Prepare. |
| 2463 | func (p *Pipeline) SendPrepare(name, sql string, paramOIDs []uint32) { |