teomutex

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

README

teomutex

Golang package teomutex is Teonet Cloud Mutex baset on Google Cloud Storage. It can be used to serialize computations anywhere on the global internet.

GoDoc Go Report Card

How to install it

The reference implementation in this repo is written in Go. To use teomutex in a Go program, install the code using this command: go get -u github.com/marcacohen/teomutex.

How to use it

  • Create Google Cloud Storage bucket in which lock objects will be stored. Use next command to create backet: gsutil mb gs:mutex. By default the teomutex uses the "mutex" backet name. To use another backet name set it in second parameter of the teomutex.NewMutex function.

  • In your application import the github.com/teonet/teomutex package, and create new mutex:

    // Creates new Teonet Mutex object.
    m, err := teomutex.NewMutex("test/lock/some_object")
    if err != nil {
        // Process error
        return
    }
    defer m.Close()
  • Use the m.Lock and m.Unlock functions to lock and unlock:
    // Lock mutex
    err = m.Lock()
    if err != nil {
        // Process error
        return
    }

    // Do somthing in this protected area

    // Unlock mutex
    err = m.Unlock()
    if err != nil {
        // Process error
        return
    }

You can find complete packets documentation at: https://pkg.go.dev/github.com/teonet-go/teomutex

Licence

BSD

Documentation

Overview

teomutex is a Golang package teomutex is Teonet Cloud Mutex baset on Google Cloud Storage. It can be used to serialize computations anywhere on the global internet.

How to use it:

  • Create Google Cloud Storage bucket in which lock objects will be stored. Use next command to create backet: `gsutil mb gs:mutex`. By default the teomutex uses the "mutex" backet name. To use another backet name set it in second parameter of the `teomutex.NewMutex` function.
  • In your application import the `github.com/teonet/teomutex` package, and create new mutex:

```go

// Creates new Teonet Mutex object.
m, err := teomutex.NewMutex("test/lock/some_object")
if err != nil {
	// Process error
	return
}
defer m.Close()

```

- Use the `m.Lock` and `m.Unlock` functions to lock and unlock: ```go

// Lock mutex
err = m.Lock()
if err != nil {
	//  Process error
	return
}

// Do somthing in this protected area

// Unlock mutex
err = m.Unlock()
if err != nil {
	// Process error
	return
}

```

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

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

Mutex object structure and methods receiver.

func NewMutex

func NewMutex(object string, bucket ...string) (m *Mutex, err error)

NewMutex creates new Teonet Mutex object.

Parameters:

object - is the name of lock object
backet - is the name of backet where lock objects created, by default used the "mutex" backet

func (Mutex) Close

func (m Mutex) Close() error

Close the Mutex object.

func (Mutex) Lock

func (m Mutex) Lock(object ...string) error

Lock mutex

func (*Mutex) SetLockTimeout

func (m *Mutex) SetLockTimeout(timeout time.Duration)

SetLockTimeout sets lock timeout to avoid deadlock. The default timeout is set to 10 seconds.

func (*Mutex) SetLogWriter

func (m *Mutex) SetLogWriter(w io.Writer)

SetLogWriter sets log writer used in teomutex package functions.

func (Mutex) Unlock

func (m Mutex) Unlock(object ...string) error

Unlock mutex

Jump to

Keyboard shortcuts

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