lib

package
v0.0.0-...-1fbcb59 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decompose

func Decompose(id uint64) map[string]uint64

Decompose returns a set of Snowflake ID parts.

func Do

func Do(attempts int) time.Duration

Do is a function x^e multiplied by a factor of 0.1 second. Result is limited to 2 minute.

Types

type AsyncCallHelper

type AsyncCallHelper struct {
	// contains filtered or unexported fields
}
var DefaultAsyncWithBufferHelper *AsyncCallHelper = NewAsyncCallHelper(256, 64, true)

func NewAsyncCallHelper

func NewAsyncCallHelper(maxChanLen, maxprocs int, withBuffer bool) *AsyncCallHelper

func (*AsyncCallHelper) AsyncCall

func (m *AsyncCallHelper) AsyncCall(call func() error)

type SnowFlake

type SnowFlake struct {
	LastStamp int64 // 记录上一次ID的时间戳
	MachineID int64 // 该节点的ID  工作机器ID(0~31)
	Sequence  int64 // 当前毫秒已经生成的ID序列号(从0 开始累加) 1毫秒内最多生成4095个ID
	// contains filtered or unexported fields
}

func NewSnowFlake

func NewSnowFlake(machineID int64) (*SnowFlake, error)

分布式情况下,我们应通过外部配置文件或其他方式为每台机器分配独立的id

func (*SnowFlake) NextID

func (w *SnowFlake) NextID() (uint64, error)

type Worker

type Worker struct {
	Num int
	// contains filtered or unexported fields
}

func NewWork

func NewWork(workNum int, ctx context.Context) *Worker

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

func (*Worker) Send

func (w *Worker) Send(num int)

Jump to

Keyboard shortcuts

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