Categorygithub.com/codeskyblue/safetime
modulepackage
0.2.0
Repository: https://github.com/codeskyblue/safetime.git
Documentation: pkg.go.dev

# README

safetime

This lib is try to solve go issue time timer.Reset is not thread safe

Here is a sample code

package main

import (
	"time"
)

func main() {
	tm := time.NewTimer(1 * time.Millisecond)
	for i := 0; i < 2; i++ {
		go func() {
			for {
				tm.Reset(1 * time.Millisecond)
			}
		}()
	}
	for {
		<-tm.C
	}
}

This code will be panic if you try to run.

With this lib safetime it will not panic any more.

package main

import (
	time "github.com/codeskyblue/safetime"
)

func main() {
	tm := time.NewTimer(1 * time.Millisecond)
	for i := 0; i < 2; i++ {
		go func() {
			for {
				tm.Reset(1 * time.Millisecond)
			}
		}()
	}
	for {
		<-tm.C
	}
}

panic in go 1.11

LICENSE

MIT

# Functions

No description provided by the author

# Structs

SafeTime add thread-safe for time.Timer.