concurrency

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package concurrency provides support for distributed concurrency capabilities

The goal is to simplify the development of concurrency capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartEmbedEtcd

func StartEmbedEtcd(config *config.Config) (etcd *embed.Etcd, err error)

StartEmbedEtcd start embed etcd

Types

type EtcdMutex

type EtcdMutex struct {
	// contains filtered or unexported fields
}

EtcdMutex implements a distributed lock based on etcd.

func NewEtcdMutex

func NewEtcdMutex(chainID string, addrs []string) (*EtcdMutex, error)

NewEtcdMutex new a mutex for a etcd implementation.

func (*EtcdMutex) Close

func (e *EtcdMutex) Close() error

Close close the lock

func (*EtcdMutex) Lock

func (e *EtcdMutex) Lock(sequence int64) (int64, error)

Lock get lock

func (*EtcdMutex) Unlock

func (e *EtcdMutex) Unlock(success bool) (err error)

Unlock unlock the lock

func (*EtcdMutex) Update

func (e *EtcdMutex) Update(sequence int64) error

Update update the lock

type Mutex

type Mutex interface {
	// Lock get lock through chain id and sequence
	//
	// If it returned an error, indicates that the call failed.
	// Whether successful or not,
	// the current sequence saved in the distributed lock is returned.
	// Negative sequence(<0) are returned unless there are some unknown exceptions.
	Lock(sequence int64) (int64, error)

	// Update update the sequence saved in the distributed lock.
	Update(sequence int64) error

	// Unlock after successfully acquiring the lock, the lock needs to be unlocked.
	//
	// If it returned an error, indicates that the call failed.
	Unlock(success bool) error

	// Close close the lock
	Close() error
}

Mutex distributed lock interface

func NewMutex

func NewMutex(name, address string) (m Mutex, err error)

NewMutex new mutex based on configuration.

type StandaloneMutex

type StandaloneMutex struct {
	// contains filtered or unexported fields
}

StandaloneMutex implements a standalone version for single process.

func NewStandaloneMutex

func NewStandaloneMutex(name string) *StandaloneMutex

NewStandaloneMutex new a mutex for a standalone implementation.

func (*StandaloneMutex) Close

func (s *StandaloneMutex) Close() error

Close close the lock

func (*StandaloneMutex) Lock

func (s *StandaloneMutex) Lock(sequence int64) (int64, error)

Lock get lock

func (*StandaloneMutex) Unlock

func (s *StandaloneMutex) Unlock(success bool) error

Unlock unlock the lock

func (*StandaloneMutex) Update

func (s *StandaloneMutex) Update(sequence int64) error

Update update the sequence in lock

Jump to

Keyboard shortcuts

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