Ken 1 сар өмнө
parent
commit
353c31a3ab
3 өөрчлөгдсөн 31 нэмэгдсэн , 0 устгасан
  1. 5 0
      date.go
  2. 24 0
      pool.go
  3. 2 0
      task.go

+ 5 - 0
date.go

@@ -88,6 +88,11 @@ func StrToLocationDate(s string) (t time.Time, err error) {
 	return
 }
 
+// Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC.
+func Unix(sec, nsec int64) time.Time {
+	return time.Unix(sec, nsec)
+}
+
 // IsWeekEnd 日期是否周末
 func IsWeekEnd(d time.Weekday) bool {
 	day := int(d)

+ 24 - 0
pool.go

@@ -0,0 +1,24 @@
+package myth
+
+import (
+	"bytes"
+	"sync"
+)
+
+var bufferPool = sync.Pool{
+	New: func() any {
+		return new(bytes.Buffer)
+	},
+}
+
+// NewBuffer alloc *bytes.Buffer from pool
+func NewBuffer() *bytes.Buffer {
+	b := bufferPool.Get().(*bytes.Buffer)
+	b.Reset()
+	return b
+}
+
+// PutBuffer release *bytes.Buffer to pool
+func PutBuffer(b *bytes.Buffer) {
+	bufferPool.Put(b)
+}

+ 2 - 0
task.go

@@ -85,6 +85,8 @@ func (t *Task) do(ctx context.Context, nsec int64) {
 			continue
 		}
 
+		// interval == 0
+
 		// 小时、天任务
 		hour, minute, second = v.Timing()
 		if second == s {