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 ¶
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) SetLockTimeout ¶
SetLockTimeout sets lock timeout to avoid deadlock. The default timeout is set to 10 seconds.
func (*Mutex) SetLogWriter ¶
SetLogWriter sets log writer used in teomutex package functions.
Click to show internal directories.
Click to hide internal directories.