All Projects → RussellLuo → goodtimer

RussellLuo / goodtimer

Licence: other
Golang timer for humans.

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to goodtimer

inspector-metrics
Typescript metrics / monitoring library
Stars: ✭ 19 (-38.71%)
Mutual labels:  timer
flipdown-timer-card
Flipdown Timer Card for Home Assistant Lovelace
Stars: ✭ 28 (-9.68%)
Mutual labels:  timer
vue-circular-count-down-timer
a count down timer library for vue.js
Stars: ✭ 45 (+45.16%)
Mutual labels:  timer
timezz
With this plugin, you can easily make a stopwatch or timer on your site. Just init, style and enjoy.
Stars: ✭ 35 (+12.9%)
Mutual labels:  timer
pauseable.js
Create event emitters, intervals, and timeouts that can be paused and resumed.
Stars: ✭ 44 (+41.94%)
Mutual labels:  timer
gnome-shell-teatime
No description or website provided.
Stars: ✭ 34 (+9.68%)
Mutual labels:  timer
GymWorkoutManager
💪A functional Gym workout timer ❤️
Stars: ✭ 16 (-48.39%)
Mutual labels:  timer
custom timer
A Flutter package to create a customizable timer.
Stars: ✭ 25 (-19.35%)
Mutual labels:  timer
asynchronous
A D port of Python's asyncio library
Stars: ✭ 35 (+12.9%)
Mutual labels:  timer
libmcu
A toolkit for firmware development
Stars: ✭ 33 (+6.45%)
Mutual labels:  timer
bestest timer
This is an awesome punch clock/timer plugin for Redmine. It's great. It's the bestest.
Stars: ✭ 15 (-51.61%)
Mutual labels:  timer
LiveSplitOne
A version of LiveSplit that works on a lot of platforms.
Stars: ✭ 172 (+454.84%)
Mutual labels:  timer
timerlab
⏰ A simple and customizable timer
Stars: ✭ 94 (+203.23%)
Mutual labels:  timer
timer-machine-android
⏲ A highly customizable interval timer app for Android
Stars: ✭ 32 (+3.23%)
Mutual labels:  timer
advpl-MsgTimer
Função AdvPL de mensagens (Alert, Info, Stop, Success, YesNo e NoYes) com Timer para fechamento automático
Stars: ✭ 17 (-45.16%)
Mutual labels:  timer
flowloop
A Pomodoro-like timer for hyper-productivity
Stars: ✭ 69 (+122.58%)
Mutual labels:  timer
tm
timers and timeline
Stars: ✭ 31 (+0%)
Mutual labels:  timer
react-component-countdown-timer
This is a simple count down timer react component.
Stars: ✭ 18 (-41.94%)
Mutual labels:  timer
Aospdeskclock
Fork of aosp deskclock: alarm,clock, timer,stopwatch
Stars: ✭ 28 (-9.68%)
Mutual labels:  timer
redtimer
RedTimer - Redmine Time Tracker
Stars: ✭ 59 (+90.32%)
Mutual labels:  timer

goodtimer

Golang timer for humans.

goodtimer is a thin wrapper around the standard time.Timer, and it tries to play two roles:

  1. A library that helps you use time.Timer more easily.
  2. As well as a demonstration that shows you how to use time.Timer correctly.

Installation

$ go get -u github.com/RussellLuo/goodtimer

Documentation

For usage and examples see the Godoc.

Why?!

TL;DR: The standard time.Timer is hard to use correctly.

Timer.Stop

Per the documentation of Timer.Stop, to stop the timer created with NewTimer, you need to check the return value and drain the channel if necessary:

if !t.Stop() {
	<-t.C
}

But the draining operation will be blocked if the the program has already received from the Timer's channel before. So someone suggests doing a non-blocking draining:

if !t.Stop() {
	select {
	case <-t.C: // try to drain the channel
	default:
	}
}

However, there is a race condition between draining the channel and sending time into the channel, which may lead to a undrained channel.

Timer.Reset

To reset a timer, is must have expired or be stopped before. So Timer.Reset has almost the same issue with Timer.Stop.

Solutions

Finally, as Russ Cox suggested (here and here), the correct way to use time.Timer is:

  • All the Timer operations (Timer.Stop, Timer.Reset and receiving from or draining the channel) should be done in the same goroutine.
  • The program should manage an extra status showing whether it has received from the Timer's channel or not.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].