synx

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2018 License: MIT Imports: 1 Imported by: 6

README

Synx

Simple wrappers to allow concurrent writes to scalar types.

Install

go get github.com/leaanthony/synx

Usage

Each supported type has a New function, EG NewInt(). This takes an intial value. Accessing the value is simply through GetValue() and SetValue().

New

Create a new Synx wrapper for type.

 var a = synx.NewInt(0)
GetValue()

Return the current value of the scalar.

 var b := a.GetValue()

SetValue()

Update the current value of the scalar.

 var c := a.SetValue(100)

Lock() / Unlock()

Enables / Disables the synchronisation locks for the scalar

 c.Lock()
 // Perform operations requiring exclusive lock 
 c.Unlock()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

Bool represents a boolean value

func NewBool

func NewBool(value bool) *Bool

NewBool creates a new wrapper type for a Bool value

func (*Bool) GetValue

func (s *Bool) GetValue() (value bool)

GetValue returns the current value

func (*Bool) Lock

func (l *Bool) Lock()

Lock the mutex

func (*Bool) SetValue

func (s *Bool) SetValue(value bool)

SetValue sets the value to the given value

func (*Bool) Unlock

func (l *Bool) Unlock()

Unlock the mutex

type Int

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

Int represents an int type

func NewInt

func NewInt(value int) *Int

NewInt creates a new wrapper type for an int value

func (*Int) GetValue

func (s *Int) GetValue() (value int)

GetValue returns the value originally given

func (*Int) Lock

func (l *Int) Lock()

Lock the mutex

func (*Int) SetValue

func (s *Int) SetValue(value int)

SetValue sets the value

func (*Int) Unlock

func (l *Int) Unlock()

Unlock the mutex

type String

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

String represents a string type

func NewString

func NewString(value string) *String

NewString creates a new wrapper for a string value

func (*String) GetValue

func (s *String) GetValue() (value string)

GetValue returns the value originally given

func (*String) Lock

func (l *String) Lock()

Lock the mutex

func (*String) SetValue

func (s *String) SetValue(value string)

SetValue sets the value

func (*String) Unlock

func (l *String) Unlock()

Unlock the mutex

type StringSlice

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

StringSlice represents a string slice type

func NewStringSlice

func NewStringSlice(value []string) *StringSlice

NewStringSlice creates a new wrapper for a string slice

func (*StringSlice) GetElement

func (s *StringSlice) GetElement(index int) (value string)

GetElement returns the value at the given element index

func (*StringSlice) GetValue

func (s *StringSlice) GetValue() (value []string)

GetValue returns the value originally given

func (*StringSlice) Length

func (s *StringSlice) Length() (length int)

Length returns the number of elements in the slice

func (*StringSlice) Lock

func (l *StringSlice) Lock()

Lock the mutex

func (*StringSlice) SetValue

func (s *StringSlice) SetValue(value []string)

SetValue sets the value

func (*StringSlice) Unlock

func (l *StringSlice) Unlock()

Unlock the mutex

Jump to

Keyboard shortcuts

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