package common

import (
	"sync"
	"sync/atomic"
	"time"
)

var (
	taskId = new(atomic.Uint64)
	requestId uint64
	requestId_lock = new(sync.Mutex)
)

func init() {
	taskId.Store(uint64(time.Now().Unix()))
}

func NewTaskId() uint64 {
	return taskId.Add(1)
}

func NewRequestId() uint64 {
	requestId_lock.Lock()
	defer requestId_lock.Unlock()
	now := uint64(time.Now().Unix())
	if now > requestId {
		requestId = now
	} else {
		requestId++
	}
	return requestId
}