sync

package
v0.0.0-...-917641f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NonBlocking

func NonBlocking(s ops.Store) ops.Store

NonBlocking converts a regular store into a non-blocking store

This modifies the GetSince call to return immediately and fetch results asynchronously.

func Reliable

func Reliable(s ops.Store, opts ...Option) ops.Store

Reliable is used by Stream() to work with a reliable store.

Reliable takes a store that can fail and converts it to a reliable store. All Append() calls return success immediately with background attempts to deliver/retry.

GetSince is modified to retry up to the specified timeout.

Note: the only options that affects Reliable() are WithBackoff() and WithLog()

func Stream

func Stream(store ops.Store, opts ...Option) streams.Stream

Stream converts an ops Store into a stream.

Calling Append() on the Stream is asynchronously appended to the Store and remote changes are also automatically merged into the returned stream.

Sync works with a Transformed store. A raw store can be auto transformed via the WithAutoTransform option.

Additional sync options can be used to configure the behavior.

The returned close function can be used to shutdown the synchronization but the underlying store still needs to be separately released.

Types

type Config

type Config struct {
	// A reliable ops store.
	ops.Store

	// AutoTransform is off by default but can be set to true to
	// automatically transform the provided store
	AutoTransform bool

	// NonBlocking is inititally off but can be set to true to
	// make GetSince non-blocking
	NonBlocking bool
	ops.Cache

	// Session state
	Version    int
	Pending    []ops.Op
	MergeChain []ops.Op

	// logger
	log.Log

	// Session state notifier
	Notify func(version int, pending, mergeChain []ops.Op)

	// Backoff configures the exponential backoff settings
	Backoff struct {
		Rand         func() float64
		Initial, Max time.Duration
	}
}

Config defines the configuration options for synchronization

type Option

type Option func(c *Config)

Option can be used to configure Sync behavior

See WithSession and WithCloseNotify

func WithAutoTransform

func WithAutoTransform(cache ops.Cache) Option

WithAutoTransform specifies that the initial store yields untransformed operations and must be automatically transformed.

The cache is required

func WithBackoff

func WithBackoff(rng func() float64, initial, max time.Duration) Option

WithBackoff configures the binary-exponential backoff settings

func WithLog

func WithLog(l log.Log) Option

WithLog configures the logger to use

func WithNonBlocking

func WithNonBlocking(nonBlock bool) Option

WithNonBlocking sets the non-blocking flag to true.

This makes Pull() return synchronously with any remote fetches in the background.

func WithNotify

func WithNotify(fn func(version int, pending, mergeChain []ops.Op)) Option

WithNotify configures a callback to be called when the session state changes. In particular, this is called when the session is closed.

func WithSession

func WithSession(version int, pending, mergeChain []ops.Op) Option

WithSession configures the connector to start with the provided version and pending instead of starting from scrach

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL