MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / generateContinuousChanges

Method generateContinuousChanges

rest/changes_api.go:472–483  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
472func (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
485func (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

Calls 3

ctxMethod · 0.95
logStatusMethod · 0.95
GenerateChangesFunction · 0.92

Tested by

no test coverage detected