safetime

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Timer added in v0.2.0

type Timer struct {
	*time.Timer
	// contains filtered or unexported fields
}

SafeTime add thread-safe for time.Timer

func NewTimer added in v0.2.0

func NewTimer(d time.Duration) *Timer

func (*Timer) Reset added in v0.2.0

func (t *Timer) Reset(d time.Duration) bool

Reset is thread-safe now

Jump to

Keyboard shortcuts

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