This is the core functionality of both the HTTP and WebSocket-based continuous change feed. It defers to a callback function 'send()' to actually send the changes to the client. It will call send(nil) to notify that it's caught up and waiting for new changes, or as a periodic heartbeat while waiting
(inChannels base.Set, options db.ChangesOptions, send func([]*db.ChangeEntry) error)
| 470 | // It will call send(nil) to notify that it's caught up and waiting for new changes, or as |
| 471 | // a periodic heartbeat while waiting. |
| 472 | func (h *handler) generateContinuousChanges(inChannels base.Set, options db.ChangesOptions, send func([]*db.ChangeEntry) error) (error, bool) { |
| 473 | // Ensure continuous is set, since generateChanges now supports both continuous and one-shot |
| 474 | options.Continuous = true |
| 475 | err, forceClose := db.GenerateChanges(h.ctx(), h.collection, inChannels, options, nil, send) |
| 476 | if sendErr, ok := err.(*db.ChangesSendErr); ok { |
| 477 | h.logStatus(http.StatusOK, fmt.Sprintf("Write error: %v", sendErr)) |
| 478 | return nil, forceClose // error is probably because the client closed the connection |
| 479 | } else { |
| 480 | h.logStatus(http.StatusOK, "OK (continuous feed closed)") |
| 481 | } |
| 482 | return err, forceClose |
| 483 | } |
| 484 | |
| 485 | func (h *handler) sendContinuousChangesByHTTP(inChannels base.Set, options db.ChangesOptions) (error, bool) { |
| 486 | // Setting a non-default content type will keep the client HTTP framework from trying to sniff |
no test coverage detected