mft

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 7 Imported by: 30

README

mft

some tools (golang) RWCMutex - rwmutex with TryLock(context) method
PMutex - rwmutex with TryLock(context) method and change mode between Lock and RLock
G - generator next id

RWCMutex

RWCMutex is RW mutex with TryLock method.
TryLock try locks mutex until context done. TryLock returns true when success and false when not.
LockD try locks mutex until during input duration.

PMutex

PMutex is RW mutex with TryLock method and you can Promote RLock to Lock and Reduce from Lock to RLock.
PMutex works slowly then RWCMutex

PMutex.Lock method returns lock key
You must not lose this key, because you need it to unlock.
You can use TryUnlock multiple times.

	k := mx.Lock()
    ...
	mx.TryUnlock(k)
    ...
	mx.TryUnlock(k)
	k := mx.Lock()
    ...
	mx.Unlock(k)

Error

You can create error with code and error from error

Example:

package main
import (
	"fmt"
	"github.com/myfantasy/mft"
)
func main() {
	var e error
	e = mft.ErrorCS(7, "Bond Error")
	fmt.Println(e)
	e = mft.ErrorCSE(12, "M Error", e)
	fmt.Println(e)
}
[7] Bond Error
[12] M Error    [7] Bond Error

Documentation

Index

Constants

View Source
const (
	Free int = iota
	ReadLock
	Lock
)

Lock statuses

View Source
const ErrorCommonCode int = 50000

ErrorCommonCode - no code error

Variables

View Source
var InnerErrorPrefix string = "  "

Functions

func GoTime

func GoTime() int64

GoTime - fast get time

func RvGet

func RvGet() int64

RvGet - Generate Next RV (sync)

func RvGet2

func RvGet2() int64

RvGet2 - Generate Next RV (sync)

func RvGetPart

func RvGetPart() int64

RvGetPart - Generate Next RV (sync)

Types

type Error

type Error struct {
	Code              int    `json:"code,omitempty"`
	Msg               string `json:"msg,omitempty"`
	InternalErrorText string `json:"iet,omitempty"`
	InternalError     *Error `json:"ie,omitempty"`
}

Error type with internal

func ErrorCE

func ErrorCE(code int, err error) *Error

ErrorCE make Error from any error

func ErrorCS

func ErrorCS(code int, err string) *Error

ErrorCS make Error from string

func ErrorCSE

func ErrorCSE(code int, err string, internalError error) *Error

ErrorCSE make Error from string with internal error

func ErrorE

func ErrorE(err error) *Error

ErrorE make Error from any error

func ErrorNew

func ErrorNew(msg string, internalError error) *Error

ErrorNew - Create new Error from msg and another error

func ErrorNew2

func ErrorNew2(msg string, internalError error, internal2Error error) *Error

ErrorNew2 - Create new Error

func ErrorS

func ErrorS(err string) *Error

ErrorS make Error from string

func (*Error) AppendE

func (e *Error) AppendE(errs error) *Error

AppendE append next error level saving code

func (*Error) AppendS

func (e *Error) AppendS(errs string) *Error

AppendS append next error level saving code

func (*Error) Error

func (e *Error) Error() string

Error implement error interface

type ErrorProvider

type ErrorProvider interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})

	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Fatalln(args ...interface{})
	Panicln(args ...interface{})
}

ErrorProvider interface for error provider mostly for background processes

type G

type G struct {
	AddValue int64
	// contains filtered or unexported fields
}

G Generator

func (*G) RvGet

func (g *G) RvGet() int64

RvGet - Generate Next RV (sync)

func (*G) RvGet2

func (g *G) RvGet2() int64

RvGet2 - Generate Next RV (sync)

func (*G) RvGetPart

func (g *G) RvGetPart() int64

RvGetPart - Generate Next RV (sync) partitioned by (x%10000)/10

type PMutex

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

PMutex - mutex with identity of lock read write mutex with context and change Priority

func (*PMutex) Lock

func (m *PMutex) Lock() (i int64)

Lock - locks mutex

func (*PMutex) LockD

func (m *PMutex) LockD(d time.Duration) (i int64, ok bool)

LockD - try locks mutex with time duration

func (*PMutex) Promote

func (m *PMutex) Promote(i int64) bool

Promote - promotes read lock mutex to lock

func (*PMutex) PromoteD

func (m *PMutex) PromoteD(d time.Duration, i int64) bool

PromoteD - promotes read lock mutex to lock with time duration

func (*PMutex) RLock

func (m *PMutex) RLock() (i int64)

RLock - read locks mutex

func (*PMutex) RLockD

func (m *PMutex) RLockD(d time.Duration) (i int64, ok bool)

RLockD - read locks mutex with time duration

func (*PMutex) RTryLock

func (m *PMutex) RTryLock(ctx context.Context) (i int64, ok bool)

RTryLock - read locks mutex with context

func (*PMutex) Reduce

func (m *PMutex) Reduce(i int64) bool

Reduce - reduce lock mutex to read lock

func (*PMutex) Status

func (m *PMutex) Status(i int64) int

Status - status of lock 0 - free (not lock) 1 - read lock 2 - (write) lock

func (*PMutex) TryLock

func (m *PMutex) TryLock(ctx context.Context) (i int64, ok bool)

TryLock - try locks mutex with context

func (*PMutex) TryPromote

func (m *PMutex) TryPromote(ctx context.Context, i int64) bool

TryPromote - promotes read lock mutex to lock with context

func (*PMutex) TryUnlock

func (m *PMutex) TryUnlock(i int64)

TryUnlock - unlocks mutex without panic

func (*PMutex) Unlock

func (m *PMutex) Unlock(i int64)

Unlock - unlocks mutex (also works as RUnlock)

type RWCMutex

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

RWCMutex - Read Write Context Mutex

func (*RWCMutex) Lock

func (m *RWCMutex) Lock()

Lock - locks mutex

func (*RWCMutex) LockD

func (m *RWCMutex) LockD(d time.Duration) bool

LockD - try locks mutex with time duration

func (*RWCMutex) RLock

func (m *RWCMutex) RLock()

RLock - read locks mutex

func (*RWCMutex) RLockD

func (m *RWCMutex) RLockD(d time.Duration) bool

RLockD - try read locks mutex with time duration

func (*RWCMutex) RTryLock

func (m *RWCMutex) RTryLock(ctx context.Context) bool

RTryLock - try read locks mutex with context

func (*RWCMutex) RUnlock

func (m *RWCMutex) RUnlock()

RUnlock - unlocks mutex

func (*RWCMutex) TryLock

func (m *RWCMutex) TryLock(ctx context.Context) bool

TryLock - try locks mutex with context

func (*RWCMutex) Unlock

func (m *RWCMutex) Unlock()

Unlock - unlocks mutex

Directories

Path Synopsis
Package im - int math simple operations lake max min etc for int
Package im - int math simple operations lake max min etc for int

Jump to

Keyboard shortcuts

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